Search code examples
haskelltypeshappstack

Haskell, String vs ...String?


I'm currently following the Happstack lite tutorial from their website. http://happstack.com/page/view-page-slug/9/happstack-lite-tutorial

Right now, I'm implementing the echo function, and the compiler is giving me an error message that I don't really understand. Here's my code:

echo :: ServerPart Response
echo =
    path $ \(msg :: String) ->
        ok $ template "echo" $ do
            h1 "Echo service"
            p "Giant, Haskell style Papagallo"
            p msg

And here's the error message:

src/motiondude.hs:35:15:
    Couldn't match type `[Char]' with `Text.Blaze.Internal.MarkupM ()'
    Expected type: Html
      Actual type: String
    In the first argument of `p', namely `msg'
    In a stmt of a 'do' block: p msg
    In the second argument of `($)', namely
      `do { h1 "Echo service";
            p "Giant, Haskell style Papagallo";
            p msg }'

I thought that a quote-enclosed "thing", like the

"Giant, Haskell style Papagallo"

was a string. Yet, from what I understand from the compiler error, p will not accept a string as argument. Can someone explain this to me?


Solution

  • The problem is you seem to have enabled the OverloadedString extensions which means that

    "foo" :: IsString a => a
    

    To coerce a plain old String to anything implementing IsString just use fromString. In this case however, Happstack has a function html which looks more appropriate.