On Sat, Mar 24, 2012 at 7:26 PM, Goswin von Brederlow <goswin-...@web.de> wrote:
>
> So why not allow mutable in variant types and some equivalence with
> records? For example:
>
> type <name> = <Constructor> of [mutable] <type>[:label] [| ...]
>
> as in:
>
> type foo =
>  | Bar of int:i * mutable int:bar_used
>  | Baz of float:f * mutable int:baz_used
>
> let use x =
>  match x with
>    | Bar bar ->
>        bar.bar_used <- bar.bar_used + 1
>    | Baz baz ->
>        baz.baz_used <- baz.baz_used + 1
>
> let print x =
>  use x;
>  match x with
>  | Bar bar -> Printf.printf "%d\n" bar.i
>  | Baz baz -> Printf.printf "%f\n" baz.f
>
> The label is optional and any types in the constructor without label
> would be translated into anonymous fields in a record that are
> ineaccessible.
>
>  type foo = Foo of int * mutable int:used
>
> would be equivalent to { _ : int; mutable used : int; }
>
> Taking it one step wurther one could even allow:
>
> let bar = { i = 1; bar_used = 0; }
> let foo = Bar bar
> let foo = let Bar bar = foo in Bar { bar with i = 2; }
>
>
> What do you think?

I'm not sure about mutable but I'd appreciate labels :D


-- 
Caml-list mailing list.  Subscription management and archives:
https://sympa-roc.inria.fr/wws/info/caml-list
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
Bug reports: http://caml.inria.fr/bin/caml-bugs

Reply via email to