If I have the code below, how do I get rid of the last comma in the output? Is there a way to see where in the loop I am and whether I am at the end?
{-# LANGUAGE QuasiQuotes #-}
import Text.Blaze.Html.Renderer.String (renderHtml)
import Text.Hamlet (hamlet)
main = do
let xs = [1 :: Int, 2, 3]
putStrLn $ renderHtml $ [hamlet|
$forall x <- xs
$if x == 1
ONE,
$else
#{x},
|] ()
This produces ONE,2,3,
, I need ONE,2,3
. For any arbitrary list of course. Please help.
You can use
intersperse
function:That will produce this:
Note that
intersperse
will insert intermediate,
between your list. So, in the hamlet quasiquoter, you just display the list: