I'm following the Snap example project, but when I copied the example code, Stack gave me errors complaining about the use of writeBS
and how it expects a ByteString
but is given a [Char]
. So I imported a ByteString library and tried to convert all of the strings to ByteStrings using the 'fromString' method, but Stack is giving me the same error, claiming that the Srings are still [Char]
. Here's the doctored example code:
module Main where
import Snap
import Snap.Types
import Snap.Util.FileServe
import Control.Applicative
import Heist
import qualified Data.ByteString.UTF8 as BU
main :: IO ()
main = quickHttpServe site
site :: Snap ()
site =
ifTop (writeBS $ BU.fromString "hello world") <|>
route [ ("foo", writeBS $ BU.fromString "bar")
, ("echo/:echoparam", echoHandler)
] <|>
dir "static" (serveDirectory ".")
echoHandler :: Snap ()
echoHandler = do
param <- getParam "echoparam"
maybe (writeBS $ BU.fromString "must specify echo/param in URL")
writeBS $ BU.fromString param
Aucun commentaire:
Enregistrer un commentaire