Hello can someone explain to me this example from Real World Haskell of function composiiton:
data Doc = ToBeDefined deriving (Show)
(<>) :: Doc -> Doc -> Doc
a <> b = undefined
series :: Char -> Char -> (a -> Doc) -> [a] -> Doc
series open close item = enclose open close
. fsep . punctuate (char ',') . map item
-- Who does fsep compose with?
enclose :: Char -> Char -> Doc -> Doc
enclose begin end input = char begin <> input <> char <> end
I do not understand how who is the right operand of the . fsep
expression.
( . ) [who is here ] fsep
Because from the looks of it close and open are just a characters.Can you compose a function with a data type (in our case a character)?
P.S Is it possible to curry the function composition?
so enclose
accepts 3 parameters: 2 of them are already fixed open
and close
and the third one is the result of fsep
.
Basically you can do f(x1...xn-1 xn) . g(y1....yn)(k)
as long as g(y1...yn)(k)
=xn .
.
is just like any other operator.f . g == (.) f g
, and you can define sections like(f .)
and(. g)
. – chepnerf
and a functiong
they both must accept a parameter.In this case its more likef
accepts 3 parameters ,of which 2 are already fixed and 1 is taken fromg
x - where x is the third parameter. – Bercovici Adrian( f(x1...xn-1) . g(y1...yn) ) (k)
as long asg(y1...yn)(k) = xn
. ---- also, it probably should have beenenclose begin end input = char begin <> input <> char end
. – Will Ness