[mercury-users] typeclass constraint on type definition... wrong
Mark Anthony BROWN
dougl at cs.mu.OZ.AU
Thu May 27 13:49:19 AEST 1999
Robert Bossy writes:
>
> Hello,
>
> I tried the following
>
> :- typeclass foo(T) where [].
> :- type bar(T) ---> bar(T) <= foo(T).
>
>
> I meant a declaration of the type bar, parametric on the type variable T =
> since T is an instance of typeclass foo.
> And it didn't work...
> Is it semantically wrong? If not how to write it?
>
You can just leave the type variable T unconstrained in the type definition.
Any predicate that wishes to use bar(T) as an argument type should
place the constraint on it there. Eg:
:- type bar(T) ---> bar(T).
:- pred pred_that_uses_bar(bar(T), ...) <= foo(T).
:- mode pred_that_uses_bar(in, ...) is detism.
> The error is "undefined type foo/1"... so what does
>
> :- type foo(T) ---> foo(T).
> :- type bar(T) ---> bar(T) <= foo(T).
>
> mean?
>
The second declaration parses as
:- type bar(T) ---> (bar(T) <= foo(T)).
It defines the type bar(T), for all T, which has one functor '<='.
This functor takes two arguments, one of type bar(T) and the other
of type foo(T).
Cheers,
Mark
--
Mark Brown (dougl at cs.mu.oz.au) )O+ | For Microsoft to win,
MEngSc student, | the customer must lose
Dept of Computer Science, Melbourne Uni | -- Eric S. Raymond
--------------------------------------------------------------------------
mercury-users mailing list
post: mercury-users at cs.mu.oz.au
administrative address: owner-mercury-users at cs.mu.oz.au
unsubscribe: Address: mercury-users-request at cs.mu.oz.au Message: unsubscribe
subscribe: Address: mercury-users-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------
More information about the users
mailing list