[Haskell-cafe] Exercise in point free-style

Donald Bruce Stewart dons at cse.unsw.edu.au
Fri Sep 1 22:02:06 EDT 2006


haskell:
> Hello,
> 
> I was just doing Exercise 7.1 of Hal Daum?'s very good "Yet Another 
> Haskell Tutorial". It consists of 5 short functions which are to be 
> converted into point-free style (if possible).
> 
> It's insightful and after some thinking I've been able to come up with 
> solutions that make me understand things better.
> 
> But I'm having problems with one of the functions:
> 
> func3 f l = l ++ map f l
> 
> Looks pretty clear and simple. However, I can't come up with a solution. 
> Is it even possible to remove one of the variables, f or l? If so, how?

The solution is to install lambdabot ;)

Point free refactoring:
    lambdabot> pl func3 f l = l ++ map f l
    func3 = ap (++) . map

Find the type:
    lambdabot> type ap (++) . map
    forall b. (b -> b) -> [b] -> [b]

Get some free theorems:
    lambdabot> free f :: (b -> b) -> [b] -> [b]
    f . g = h . f => map f . f g = f h . map f

:)

-- Don


More information about the Haskell-Cafe mailing list