実践Haskell HaskellでのHTTPリクエストの作成 プロジェクトを管理する LANGUAGEプラグマ、OverloadedStrings
入門Haskellプログラミング (Will Kurt(著)、株式会社クイープ(監修、翻訳)、翔泳社)のUNIT7(実践Haskell)、LESSON 39(HaskellでのHTTPリクエストの作成)、39.1(プロジェクトを管理する)Q39-1の解答を求めてみる。
package.yaml
name: http-lesson
version: 0.1.0.0
github: "githubuser/http-lesson"
license: BSD3
author: "Author name here"
maintainer: "example@example.com"
copyright: "2021 Author name here"
extra-source-files:
- README.md
- ChangeLog.md
# Metadata used when publishing your package
# synopsis: Short description of your package
# category: Web
# To avoid duplicated efforts in documentation and dealing with the
# complications of embedding Haddock markup inside cabal files, it is
# common to point users to the README.md file.
description: Please see the README on GitHub at <https://github.com/githubuser/http-lesson#readme>
dependencies:
- base >= 4.7 && < 5
library:
source-dirs: src
executables:
http-lesson-exe:
main: Main.hs
source-dirs: app
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- http-lesson
- bytestring
- http-conduit
tests:
http-lesson-test:
main: Spec.hs
source-dirs: test
ghc-options:
- -threaded
- -rtsopts
- -with-rtsopts=-N
dependencies:
- http-lesson
コード
app/Main.hs
-- 以下のLANGUAGEプラグマを追加すればいい
{-# LANGUAGE OverloadedStrings #-}
module Main where
import qualified Data.ByteString as B
import qualified Data.ByteString.Char8 as BC
import qualified Data.ByteString.Lazy as L
import qualified Data.ByteString.Lazy.Char8 as LC
import Network.HTTP.Simple
import Lib
main :: IO ()
main = print "Hi"
入出力結果(Terminal, Zsh)
% stack exec http-lesson-exe
"Hi"
%