Friday, July 2, 2010

Real Point-free Haskell Program

Hi, it is NISHIO Hirokazu. I'm trying to make *REAL* point-free Haskell program. In other words, I want to make point-free (arguments-less) Haskell code with any point(.)

You may know, usually most of Haskell programmer use (.) operator to combine functions. However, it is not necessary. It can replace with (<*>) and const.


Prelude Control.Applicative> :t (.)
(.) :: (b -> c) -> (a -> b) -> a -> c
Prelude Control.Applicative> :t \x y z -> (const x <*> y) z
\x y z -> (const x <*> y) z :: (a -> b) -> (b1 -> a) -> b1 -> b


So anytime you want to use (.) operator, you can do it without (.)


Prelude Control.Applicative> (map . (+)) 1 [1, 2, 3]
[2,3,4]
Prelude Control.Applicative> (const map <*> (+)) 1 [1, 2, 3]
[2,3,4]


And it is also easy to remove points from float expression:


Prelude> 1.5
1.5
Prelude> 15e-1
1.5


The most biggest problem is how to remove this point.

import Control.Applicative
^

No comments: