caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Martin Jambon <martin_jambon@emailuser.net>
To: Jeffrey Cook <jeffrey.j.cook@gmail.com>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] Records with default values
Date: Wed, 23 Mar 2005 12:25:44 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.44.0503231150001.1304-100000@localhost> (raw)
In-Reply-To: <88707140050323114156bcb9fb@mail.gmail.com>

On Wed, 23 Mar 2005, Jeffrey Cook wrote:

> What I would like is the following:
>
> type bob = {
>     foo : string ;
>     bar : int := 0 ;
> }
>
> let x = { foo = "hello" }

I would go for a "create_bob" function with labelled arguments, some of
them being optional:

let rec create_bob ~foo ?(bar = 0) () =
  { foo = foo;
    bar = bar }

Implementing a syntax extension that defines "create_bob" automatically is
typically something that can be done with Camlp4 :-)

It supports recursive type definitions such as:

  type t = { x : t option = Some { x = None } }

or even (since create_t is recursive):

  type t = { x : t option = Some (create_t ~x:None ()) }

which would be expanded into:

  type t = { x : t option }
  let rec create_t ?(x = Some (create_t ~x:None ())) () = { x = x }


Martin

--
Martin Jambon, PhD
http://martin.jambon.free.fr




      reply	other threads:[~2005-03-23 20:26 UTC|newest]

Thread overview: 2+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-03-23 19:41 Jeffrey Cook
2005-03-23 20:25 ` Martin Jambon [this message]

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.44.0503231150001.1304-100000@localhost \
    --to=martin_jambon@emailuser.net \
    --cc=caml-list@inria.fr \
    --cc=jeffrey.j.cook@gmail.com \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).