Question

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?

Was it helpful?

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.

OTHER TIPS

Presumably you have OverloadedStrings on, and the literal is getting converted to an Html automatically.

If you remove the type annotation from 'msg', does it work? That seems to be your problem. On line 6, the string literal gets treated as Html, not as String. However, OverloadedStrings only affects string literals, so it won't implicitly convert the msg (which you've said is a String) to an Html.

I'm not a fan of OverloadedStrings, but that's mainly because of the IsString ByteString instanace... It just bothers me so much more than the Integral Word8 instance, even though they have almost exactly the same problems.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top