Re: optional arguments ?

"Vesa Karvonen" <[email protected]> Tue, 24 Apr 2007 09:41:17 +0300
Newsgroups gmane.comp.lang.sml.smlnj
Message-ID <[email protected]>
How about this:

  http://mlton.org/OptionalArguments

-Vesa Karvonen

On 4/24/07, brian <briand-/[email protected]> wrote:
> As part of my x3d interface I'm stuck with the task of filling in
> lots and lots of records, many of which have little used fields which
> can simply be stuffed with a reasonable default.
>
> I would like to create convenient constructor functions which assign
> reasonable defaults to the unassigned fields.
>
> What's a good method to do this in SML ?  Python (and OCAML) allow
> labelled arguments with a default assigned to unspecified args.  I
> don't believe something like this is avaiable for SML.
>
> As of right now the most practical method I can think of is to simply
> pass in an a-list to the constructor.  However even that would be
> somewhat painful since I would have to create an algebraic type for
> the second arg, e.g.
>
> datatype arg = Float of real | Int of int | String of string |
> VectorF of float vector | etc...
>
> So then I could use string * arg for the a-list.
>
> Seems somewhat clumsy.
>
> any way to do this with some clever record notation trick ?
>
>
> Thanks
>
> Brian

-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/