[mercury-users] Constructor question.
Ian MacLarty
maclarty at csse.unimelb.edu.au
Sat Apr 14 22:01:42 AEST 2012
On Sat, Apr 14, 2012 at 9:59 PM, Ian MacLarty
<maclarty at csse.unimelb.edu.au> wrote:
> On Sat, Apr 14, 2012 at 9:42 PM, Michael Richter <ttmrichter at gmail.com> wrote:
>> On 14 April 2012 19:32, Michael Richter <ttmrichter at gmail.com> wrote:
>>>
>>> On 14 April 2012 19:21, Ian MacLarty <maclarty at csse.unimelb.edu.au> wrote:
>>>>
>>>> > You can also do something like this:
>>>>
>>>>
>>>> Foo ^ bar = 10,
>>>> Foo ^ baz = "eleven",
>>>> Foo ^ quux = yes,
>>>
>>>
>>> OK, I … am duly chastened. I hadn't even thought of doing it that way. I
>>> was constantly messing with :=.
>>
>>
>> OK, I'm still lost, I'm afraid. Given this type declaration:
>>
>> :- type foo(bar::int, baz::string, quux::bool).
>>
>> How would I instantiate this using the system you show?
>>
>> :- func default_instance = (foo::out) is det.
>> default_instance = <what code do I put here?>
>>
>> I've tried a few ways to do this, with = or :=, explicitly naming the return
>> variable and separating it from the instantiation code with :- (and a few
>> other more desperate attempts) and I'm just not having any luck.
>>
>
> This works for me:
>
> :- type foo ---> foo(bar :: int, baz :: string).
> :- func default_instance = (foo::out) is det.
> default_instance = Foo :-
> Foo ^ bar = 10,
> Foo ^ baz = "eleven".
>
As does this:
:- type foo ---> foo(bar :: int, baz :: string, quux :: bool).
:- func default_instance = (foo::out) is det.
default_instance = Foo :-
Foo ^ bar = 10,
Foo ^ baz = "eleven",
Foo ^ quux = yes.
If it doesn't work for you what error do you get?
Ian.
--------------------------------------------------------------------------
mercury-users mailing list
Post messages to: mercury-users at csse.unimelb.edu.au
Administrative Queries: owner-mercury-users at csse.unimelb.edu.au
Subscriptions: mercury-users-request at csse.unimelb.edu.au
--------------------------------------------------------------------------
More information about the users
mailing list