0

been writing an application that consumes JSON data and then displays it using Happstack.

   helloBlaze :: ServerPart Response
   helloBlaze =
   ok $ toResponse $
   appTemplate "Hello, Blaze!"
            [H.meta ! A.name "keywords"
                    ! A.content "happstack, blaze, html"
            ]
            (do H.toHtml $ makeList $ getResponse)

   makeList xs = "<ul>" ++ (Items xs) ++ "</ul>"

   Items [] = ""
   Items (x:xs) = "<li>" ++ x ++ "</li>" ++ (Items xs)

The problem is when I run Happstack the response generated is the results but with html tags still showing. Any suggestions would be much appreciated.

Phillip Cloud
  • 24,919
  • 11
  • 68
  • 88

1 Answers1

1

I don't know Blaze all that well, but isn't the correct way to do this something more like

makeList xs = ul (mapM_ li xs)

That's how this works, isn't it?

(Also, don't use Items as a function name. It needs to start with a lowercase letter.)

MathematicalOrchid
  • 61,854
  • 19
  • 123
  • 220
  • Happstack_Server.hs:29:43: Couldn't match type `[Char]' with `Text.Blaze.Internal.MarkupM ()' Expected type: [H.Html] Actual type: [String] In the second argument of `($)', namely `processResponse' In the second argument of `($)', namely `makeList $ getResponse' In a stmt of a 'do' block: H.toHtml $ makeList $ processResponse –  May 07 '15 at 09:28
  • getResponse returns a string :( –  May 07 '15 at 09:29
  • try `makeList xs = ul (mapM (li . H.toHtml) xs)` – Fraser May 07 '15 at 09:35
  • Hi, sorry for the late reply, using the above code the error message I get Couldn't match type `[()]' with `()' Expected type: H.Html Actual type: Text.Blaze.Internal.MarkupM [()] In the return type of a call of `mapM' In the first argument of `H.ul', namely `(mapM (H.li . H.toHtml) xs)' In the expression: H.ul (mapM (H.li . H.toHtml) xs) –  May 11 '15 at 09:24