[Haskell-beginners] Points-free style

Lyndon Maydwell maydwell at gmail.com
Sun Jun 5 17:39:39 CEST 2011


You can use the fun (.).(.) operator :D

sumProducts :: Num a => [a] -> [a] -> a
sumProducts = ((.).(.)) sum (zipWith (*))


In all seriousness though, points-free isn't always the most readable way to go.

On Sun, Jun 5, 2011 at 11:09 PM, Alexander Shendi
<Alexander.Shendi at bawue.de> wrote:
> Hi folks,
>
> I am working my way through "Learn You a Haskell for Great Good" and
> have reached page 84, where the book recommends that you define your
> functions in a "points-free style", using the "." and "$" operators.
>
> Now I have:
>
> sumProducts' :: Num a => [a] -> [a] -> a
> sumProducts' x y = sum (zipWith (*) x y)
>
> I would like to eliminate the "x" and the "y" in the definition, but all
> I have managed to contrive is:
>
> sumProducts :: Num a => [a] -> [a] -> a
> sumProducts x = sum . zipWith (*) x
>
> How do I proceed from here? Any advice is welcome :)
>
> Many thanks in advance,
>
> /Alexander
>
>
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://www.haskell.org/mailman/listinfo/beginners
>



More information about the Beginners mailing list