Re:OCaml 4.03 will, “if all goes well”, support multicore
by lpw25 on Thursday May 21, 2015 @03:21PM
(#9584858)
OCaml has had type-directed record disambiguation for a few versions now. So you can quite easily reuse field names these days.
Re:OCaml 4.03 will, “if all goes well”, support multicore
by elihu on Thursday May 21, 2015 @04:14PM
(#9585135)
That's cool, I didn't realize they had done that. I haven't used Ocaml in quite awhile -- it's good to hear the language is still getting better.
Re:OCaml 4.03 will, “if all goes well”, support multicore
by pcwalton on Thursday May 21, 2015 @02:38PM
(#9584576)
> ML derived language that treats accessor functions as ordinary functions
OCaml is not in that tradition—field projection uses dot notation and has historically not been an ordinary function (although maybe that has changed in later versions).
Re:OCaml 4.03 will, “if all goes well”, support multicore
by gmfawcett on Thursday May 21, 2015 @04:26PM
(#9585179)
You're right, and that is still the case.
Re:OCaml 4.03 will, “if all goes well”, support multicore
by kuschku on Thursday May 21, 2015 @01:07PM
(#9583983)
Or one could use the lisp-way – and just call the functions <record-name>-<field-name>.
This avoids those problems.
Re:OCaml 4.03 will, “if all goes well”, support multicore
by gmfawcett on Thursday May 21, 2015 @01:30PM
(#9584126)
The Ocaml way would be to define the functions in separate modules (A.foo, B.foo, etc.). There are convenient syntaxes for declaring which modules are in scope in a given expression, as well as support for first-class modules (you can define functions that take modules as parameters). The module system is sophisticated, and is arguably the "power feature" of Ocaml.
Re:OCaml 4.03 will, “if all goes well”, support multicore
by creichert on Thursday May 21, 2015 @01:46PM
(#9584240)
This is what you generally see in larger haskell programs which might have a name clash (at least it's what I use):
data F = F { fName :: String }
data P = P { pName :: String }
Re:OCaml 4.03 will, “if all goes well”, support multicore
by LeonidasXIV on Thursday May 21, 2015 @05:52PM
(#9585608)
Yes, this is one of the cases where ML modules are elegant, since you can put the definition of the type into its own module, so it becomes F.t and P.t and you avoid field name clashes.
The can't-reuse-field-names thing is annoying, but claiming that it "isn't a serious language" because they made a design choice that doesn't meet your exact expectations seems kind of closed-minded to me.