[mercury-users] Constructor question.

Michael Richter ttmrichter at gmail.com
Sat Apr 14 19:08:03 AEST 2012

Given a data type like this:

:- type foo --->  foo(bar :: int, baz :: string).

Is there any way to construct a new instance of foo other than this?:

Foo = foo(10, "eleven").

Specifically is there a way to use record syntax so that I can name the
fields being given their initial value?  I've tried a variety of ways but
just can't see any way to do this that the compiler will accept and, while
not a problem for a simple record like the above type, it's a bit of a
nightmare if you're dealing with a type that has, say, a dozen members.
 I've had to do stuff that looks like this, only with a lot more lines of

Foo = foo(  10       % bar
>             "eleven" % baz
>          ).

I find this both very ugly and very error-prone.

"Perhaps people don't believe this, but throughout all of the discussions
of entering China our focus has really been what's best for the Chinese
people. It's not been about our revenue or profit or whatnot."
--Sergey Brin, demonstrating the emptiness of the "don't be evil" mantra.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.mercurylang.org/archives/users/attachments/20120414/fbf2523c/attachment.html>

More information about the users mailing list