[Haskell-cafe] proposal: point free case expressions
newsham at lava.net
Thu Nov 5 13:20:20 EST 2009
> Wouldn't it be nice if we could write point free case statements?
Yes. Haskell should automatically define destructors for
each data type you define in addition to defining constructors.
> I regularly find myself writing down something like this:
>> myFunc = anotherFunc $ \x -> case x of
>> Left err -> print err
>> Right msg -> putStrLn msg
When you define "data Either a b = Left a | Right b"
it should define "Left", "Right" and "destruct_Either" (or
whatever other name you want to give it). Of course
"destruct_Either" is just "either" from the prelude, and
you also get "maybe", but these shouldn't be prelude
functions, they should be automatically derived. Then your
points free version is just:
myFunc = anotherFunc $ either print putStrLn
In the meantime, the Data.Derive library
has a function for deriving these using TH:
This derives a non-recursive definition for recursive data types.
Its also possible to derive a similar recursive definition for
recursive data types.
> Sebastiaan Visser
More information about the Haskell-Cafe