[Haskell-cafe] Extensible records & mandatory/optional record fields

Harendra Kumar harendra.kumar at gmail.com
Thu Feb 16 03:01:21 UTC 2017

On 16 February 2017 at 07:22, Anthony Clayden <anthony_clayden at clear.net.nz>

> > On 15 February 2017 at 23:06 Harendra Kumar wrote:
> >> On 16 February 2017 at 02:31, Anthony Clayden wrote:
> For gathering params to a function, I see no need for
> extensible records.
> The params are known at compile time.
> If for a DSL you want 'optional' fields, make them Maybe's,
> with a default of Nothing.

The point is - I do not want the user to specify all parameters explicitly.
There may be a whole bunch of optional parameters in the record but only a
few are to be specified in general. I do not want 2 values and 10 Nothings
or explicit defaults there.

> >
> > I am trying to write a program which provides a friendly
> > high level DSL to the user.
> 'user' here seems to mean programmer,
> if you're looking for static guarantees.

Yes, but more of a declarative programmer.

> > I want a pure function like
> > API but instead of passing positional parameters I want
> > the user to be able to specify arguments based on keywords
> > and be able to skip any optional arguments. Something like
> > the following, name is mandatory and email is optional:
> >
> > maintainer  (#name  := "Harendra Kumar",  #email :=
> > "xyz at gmail.com")
> >
> > I can achieve this using rawr. The argument to the
> > function is an anonymous record ...
> OK. But I'm not seeing why it has to be anonymous.
> Again, if it's for a specific function, it needs specific
> parameters.
> An anonymous record might provide keywords not valid,
> as well as fail to provide keywords expected.

It does not necessarily have to be anonymous. But I see no problem if it is
anonymous. Type checking catches missing keywords or invalid keywords. The
example I gave does not have correct type constraints but by fixing it you
cannot give it incorrect keywords, I just tested it.

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/haskell-cafe/attachments/20170216/517009d0/attachment.html>

More information about the Haskell-Cafe mailing list