Lifting over record syntax

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
1 message Options
Reply | Threaded
Open this post in threaded view
|

Lifting over record syntax

Jaakko Luttinen
Hi!

Let's consider this simple data structure:

data Person = Person {name::String, age::Int} deriving Show

Now, I can create maybe-people like in applicative style:

Person <$> Just "John Doe" <*> Nothing

or in monad style:

do
   name' <- Just "John Doe"
   age' <- Nothing
   return Person {name=name', age=age'}

The problem with the first approach is that it depends on the order of
the arguments because it doesn't utilize the record syntax. The problem
with the second approach is that there's a bit of unnecessary
boilerplate (e.g., name' and age' variables).

I would like to get the benefits of the the record syntax but with
similar code simplicity as the applicative style has. Do you have ideas
is this possible? My non-working pseudo-code would look like:

Person <$> {name=Just "John Doe", age=Nothing}

But this doesn't work, it's syntax error.

Any ideas for a nice syntax?

Cheers,
Jaakko
_______________________________________________
Beginners mailing list
[hidden email]
http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners