Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I write (:)(.) on pointful form?

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.

like image 690
Niklas Avatar asked Mar 07 '23 03:03

Niklas


2 Answers

(:) (.)

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]
like image 95
melpomene Avatar answered Mar 13 '23 04:03

melpomene


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.

like image 22
Willem Van Onsem Avatar answered Mar 13 '23 05:03

Willem Van Onsem