I'm trying to understand how Haskell evalutes pp1 [1,2,3,4] to get [(1,2),(2,3),(3,4)] here:
1. xnull f [] = []
2. xnull f xs = f xs
3. (/:/) f g x = (f x) (g x)
4. pp1 = zip /:/ xnull tail
I start like this:
a) pp1 [1,2,3,4] = (zip /:/ xnull tail) [1,2,3,4] -- (rule 4).
b) (zip /:/ xnull tail) [1,2,3,4]
= (zip (xnull [1,2,3,4]) (tail) [1,2,3,4]) -- (rule 3)
c) -- I'm not sure how to continue because xnull receives a function
-- and a param, and in this case it only receives a param.
Any help?
Just keep expanding:
Operator presidence matters. You didn't specify the associativity of
(/:/)so it was defaulted to be relatively weak. Therefore,(xnull tail)bound tighter than(/:/).Also, as a side note,
(/:/)already exists in the standard library as(<*>)fromControl.Applicative. It's sufficiently general so this might be difficult to see, but theApplicativeinstance forReader(or perhaps better understood as the functionApplicative) provides this exact instance. It's also known asapfromControl.Monad.