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
Error Message after trying to fix with fromString
:
/home/jeshaitan/Personal/yapp/src/Main.hs:16:14:
Couldn't match expected type ‘BU.ByteString’
with actual type ‘[Char]’
In the expression: "foo"
In the expression: ("foo", writeBS $ BU.fromString "bar")
In the first argument of ‘route’, namely
‘[("foo", writeBS $ BU.fromString "bar"),
("echo/:echoparam", echoHandler)]’
/home/jeshaitan/Personal/yapp/src/Main.hs:17:14:
Couldn't match expected type ‘BU.ByteString’
with actual type ‘[Char]’
In the expression: "echo/:echoparam"
In the expression: ("echo/:echoparam", echoHandler)
In the first argument of ‘route’, namely
‘[("foo", writeBS $ BU.fromString "bar"),
("echo/:echoparam", echoHandler)]’
/home/jeshaitan/Personal/yapp/src/Main.hs:19:9:
Couldn't match expected type ‘BU.ByteString’
with actual type ‘[Char]’
In the first argument of ‘dir’, namely ‘"static"’
In the second argument of ‘(<|>)’, namely
‘dir "static" (serveDirectory ".")’
In the expression:
ifTop (writeBS $ BU.fromString "hello world")
<|>
route
[("foo", writeBS $ BU.fromString "bar"),
("echo/:echoparam", echoHandler)]
<|> dir "static" (serveDirectory ".")
/home/jeshaitan/Personal/yapp/src/Main.hs:23:23:
Couldn't match expected type ‘BU.ByteString’
with actual type ‘[Char]’
In the first argument of ‘getParam’, namely ‘"echoparam"’
In a stmt of a 'do' block: param <- getParam "echoparam"
In the expression:
do { param <- getParam "echoparam";
maybe
(writeBS $ BU.fromString "must specify echo/param in URL") writeBS
$ BU.fromString param }
/home/jeshaitan/Personal/yapp/src/Main.hs:25:21:
Couldn't match expected type ‘Maybe BU.ByteString’
with actual type ‘BU.ByteString’
In the second argument of ‘($)’, namely ‘BU.fromString param’
In a stmt of a 'do' block:
maybe
(writeBS $ BU.fromString "must specify echo/param in URL") writeBS
$ BU.fromString param
/home/jeshaitan/Personal/yapp/src/Main.hs:25:35:
Couldn't match type ‘Maybe BU.ByteString’ with ‘[Char]’
Expected type: String
Actual type: Maybe BU.ByteString
In the first argument of ‘BU.fromString’, namely ‘param’
In the second argument of ‘($)’, namely ‘BU.fromString param’
-- While building package yapp-0.1.0.0 using:
/home/jeshaitan/.stack/setup-exe-cache/x86_64-linux/setup-Simple-Cabal-1.22.4.0-ghc-7.10.2 --builddir=.stack-work/dist/x86_64-linux/Cabal-1.22.4.0 build exe:yapp --ghc-options " -ddump-hi -ddump-to-file"
Process exited with code: ExitFailure 1