Re: optional arguments ?

brian <briand-/[email protected]> Tue, 24 Apr 2007 07:14:26 -0700
Newsgroups gmane.comp.lang.sml.smlnj
Message-ID <[email protected]>
Very helpful.

I think I like the functional record update the best.

That way I can simply have the constructor return a "default" record  
and then just call the updater to update particular fields.

Thanks !

Brian

On Apr 23, 2007, at 11:41 PM, Vesa Karvonen wrote:

> 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/
> _______________________________________________
> Smlnj-list mailing list
> [email protected]
> https://lists.sourceforge.net/lists/listinfo/smlnj-list


-------------------------------------------------------------------------
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/