[mercury-users] typeclass constraint on type definition... wrong
David Glen JEFFERY
dgj at cs.mu.OZ.AU
Thu May 27 01:43:56 AEST 1999
On 26-May-1999, Robert Bossy <bossy at ccr.jussieu.fr> wrote:
> 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?
I can see what you are trying to declare here, but Mercury does not support
this kind of thing. Essentially, rather than noting in the type declaration
that the `T' stored in the type is meant to be in the type class `foo',
you need to add the `foo(T)' context to (most of) the predicates that
manipulate `bar(T)'s.
This is a little bit of extra typing, but we decided not to go with the
syntax you were trying to use because we didn't want to commit ourselves to
supporting something that we were not sure was a good idea (after all, it
really is just shorthand).
If you are interested, there has been a thread on the subject recently on the
Haskell mailing list (archived somewhere at http://www.haskell.org/).
> The error is "undefined type foo/1"... so what does
>
> :- type foo(T) ---> foo(T).
> :- type bar(T) ---> bar(T) <= foo(T).
>
> mean?
I suspect that the (rather unhelpful) error message comes from the above
declaration being parsed as:
:- type bar(T) ---> '<='(bar(T), foo(T)).
ie. it probably thinks that '<=' is a functor of the type `bar(T)', and
that `foo(T)' is meant to be a type, not a type class. Ulch.
(I'll see if I can make this error message any prettier).
dgj
--
David Jeffery (dgj at cs.mu.oz.au) | Marge: Homer, is this how you pictured
PhD student, | married life?
Dept. of Comp. Sci. & Soft. Eng.| Homer: Yup, pretty much... except we
The University of Melbourne | drove around in a van solving
Australia | mysteries.
--------------------------------------------------------------------------
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