Impossible to cross "" and use a non-word as a substitute for each other?

I tried to rewrite:

return $ renderHtml $ mconcat $ intersperse " " $ catMaybes links

What works fine in:

return $ renderHtml $ mconcat $ unwords $ catMaybes links

but he returns:

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 biggest yet with Haskell, but I thought, intersperse " "and unwordswhere is it easy to replace replacements with each other?

Change . Ultimately, I would like to figure out a way to use unwords... Believing why this gives me an error and how I can get around this goal! =)

+4
source share
2 answers

The unwords :: [String] -> Stringfunction only works on Strings lists . You have a list of type values MarkupM ().

, intersperse :: a -> [a] -> [a], , . OverloadedStrings pragma " " MarkupM ( IsString). intersperse , . mconcat MarkupM (). :

[Markup "foo", Markup "bar", Markup "baz"] -- returned by catMaybes links
[Markup "foo", Markup " ", Markup "bar", Markup " ", Markup "baz"] -- after intersperse
Markup "foo bar baz" -- after mconcat

unwords , , . , , HTML, .

+8

, , , LANGUAGE OverloadedStrings.

intersperse (text " ") intersperse " ".

:.

{-# LANGUAGE OverloadedStrings #-}

import Text.Blaze.Html
import Text.Blaze.Renderer.String
import Data.Maybe
import Data.List
import Data.Monoid

foo links = renderHtml $ mconcat $ intersperse " " $ catMaybes links
+2

Source: https://habr.com/ru/post/1598558/


All Articles