I've started to wrap my head around it, and rather like using it for simple situations in which I can essentially pipe the values from one output to one input. A simple example of a pointfree composition I'm comfortable with would be:
let joinLines = foldr (++) "" . intersperse "\n"
While playing with GHCI today, I wanted to see if I could compose not
and (==)
to replicate (/=)
, but I wasn't really able to reason it out. (==)
take two inputs, and not
takes one. I thought that this might work:
let ne = not . (==)
With the assumption that the single Bool
output of (==)
would go to not
, but it won't compile, citing the following error:
<interactive>:1:16:
Couldn't match expected type `Bool' with actual type `a0 -> Bool'
Expected type: a0 -> Bool
Actual type: a0 -> a0 -> Bool
In the second argument of `(.)', namely `(==)'
In the expression: not . (==)
I wish I could say it meant much to me, but all I'm getting is that maybe the second argument that's passed to (==)
is mucking things up for not
? Can anybody help me understand a little better the logic behind this composition?
(.).(.) :: (b -> c) -> (a -> a1 -> b) -> a -> a1 -> c
, orfmap . fmap
. – phipsgabler(.).(.).(.)
? – Alexey:t
, I guess? – phipsgabler