I have a hard time understanding what the function (:)(.)
in haskell does. Could someone help me write it on pointful form, and explain step by step how to get there? The first step would be to expand the (:)
so that we get ((.) :)
, but then I'm stuck.
It should be of type [(b->c)->(a->b)->a->c]->[(b->c)->(a->b)->a->c]
, but that doesn't help me, just makes me even more confused.
(:) (.)
Eta-expand:
\x -> (:) (.) x
Convert to infix notation:
\x -> (.) : x
I.e. x
must be a list and we're prepending (.)
to it (that's what :
does: it prepends an element to a list).
(.)
is a function, so x
must be a list of functions.
(.) :: (b -> c) -> (a -> b) -> a -> c
, so x
must have type
x :: [(b -> c) -> (a -> b) -> a -> c]
Well we can first convert the (:)
data constructor, and the function (.) :: (b -> c) -> (a -> b) -> a -> c
operator as a lambda expression:
(:) -> (\x y -> (x:y))
(.) -> (\f g t -> f (g t))
So that means that (:)(.)
is short for:
(\x y -> (x:y)) (\f g t -> f (g t))
So now we can replace x
with the lambda expression:
\y -> (\f g t -> f (g t)) : y
So the function is equal to ((.) :)
: a partial "cons" where we still need to fill in the tail, and the head is the dot operator.
So the type is a list of functions with the same signature as the dot operator [(b -> c) -> (a -> b) -> a -> c]
.
If we thus for example take as argument []
, we have constructed a singleton list (a list with exactly one element): the dot operator.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With