First of all, the 1-Haskell-a-Day exercise confuses me to the point of no return. The goal is to filter list items if this does not match the following. For instance.
> filterByPair [1, 2, 2, 2, 3, 3, 4]
[2,2,3]
(I tried to make two lists of offsets, fastened them into tuples and deleted tuples that did not have the same number both times, for example [(2,2), (2,2), (3,3)], etc. .) But a reasonable simple solution uses the binding operator =<<:
filterByPair :: Eq a => [a] -> [a]
filterByPair = (init =<<) . group
I am having trouble choosing this operator. I do not get the same results in ghci when I try to use it:
> init =<< [2,3,4]
No instance for (Num [b0]) arising from the literal `2'
I find that in ghci I can use, say, replicates =<<. It seems that feeding each list item into a function:
> replicate 2 =<< [2,3,4]
[2,2,3,3,4,4]
, :
> replicate 2 2
[2,2]
- , replicate, , , , fmap :
> fmap (replicate 2) [2,3,4]
[[2,2],[3,3],[4,4]]
, . -, ? filterByPair? Eq ?
, =<< ghci, ?