I was trying to rewrite:
return $ renderHtml $ mconcat $ intersperse " " $ catMaybes links
Which works just fine, into:
return $ renderHtml $ mconcat $ unwords $ catMaybes links
but it is returning:
Couldn't match type ‘Char’
with ‘blaze-markup-0.7.0.2:Text.Blaze.Internal.MarkupM ()’
Expected type: H.Html
Actual type: Char
In the second argument of ‘($)’, namely
‘mconcat $ unwords $ catMaybes links’
In the second argument of ‘($)’, namely
‘renderHtml $ mconcat $ unwords $ catMaybes links’
In a stmt of a 'do' block:
return $ renderHtml $ mconcat $ unwords $ catMaybes links
I'm not the greatest with Haskell yet, but I thought intersperse " "
and unwords
where just drop in replacements for one another?
Edit: Ultimately, I'd like to figure out a way to use unwords
... Figuring out why it's giving me the error and how I can work around it is the goal! =)
The
unwords :: [String] -> String
function only works on lists ofString
s. What you have is a list of values of typeMarkupM ()
.The reason why
intersperse :: a -> [a] -> [a]
works is that it works of list on any type. WithOverloadedStrings
pragma the" "
value has typeMarkupM
(because that type has an instance forIsString
). Theintersperse
function takes a list of these markup values and puts spaces in between them but still returns a list of markup values. Finallymconcat
joins the list into a single value still of typeMarkupM ()
. With some pseudo data constructor you can imagine the values like this:There is no easy way to get
unwords
to work in this case as you don't have strings and converting to strings would lose you some benefits. Having the markup encapsulated in appropriate wrapper makes sure that you do not produce not well-formed HTML, for example.