Mercury Bugs - mercury | |||||
View Issue Details | |||||
ID | Project | Category | View Status | Date Submitted | Last Update |
0000185 | mercury | Bug | public | 2011-02-03 17:45 | 2011-02-16 14:00 |
Reporter | mgiuca | ||||
---|---|---|---|---|---|
Assigned To | |||||
Priority | normal | Severity | major | Reproducibility | always |
Status | confirmed | Resolution | open | ||
Platform | OS | OS Version | |||
Product Version | |||||
Target Version | Fixed in Version | ||||
Summary | 0000185: Cannot make typeclass instance for parameterised equivalence type | ||||
Description | It seems that it is impossible to create a typeclass instance for any type that is all of the following: 1. parameterised, and 2. declared in another module to the instance declaration, and 3. declared abstractly and defined in the "implementation" section, and 4. defined as an equivalence type (==). Notably, this includes the 'set' type. I have created a tiny self-contained example: In the file foo.m: :- module foo. :- interface. :- type foo(T). :- implementation. :- type foo(T) == bar(T). :- type bar(T) ---> bar. In the file problem.m: :- module problem. :- interface. :- typeclass myclass(T) where [ func f(T) = int ]. :- implementation. :- import_module foo. :- instance myclass(foo(T)) where [ f(_) = 4 ]. Notice that the type 'foo' is parameterised, abstract, and defined as an equivalence to bar. In the other module, I am attempting to make foo(T) an instance of myclass. 'foo' compiles properly, but compiling 'problem' leads to this nonsensical error: problem.m:013: In instance declaration for `problem.myclass(foo.foo(T))': problem.m:013: the first arg contains a type variable which is used in problem.m:013: another arg With -E, it explains, "types in instance declarations must be functors with distinct variables as arguments". If I am reading this correctly, it is telling me that I have used the type variable `T' in multiple arguments to foo, which can't be true because it only has one argument. For a real-world example, in 'problem', replace 'foo' with 'set'; the same error arises. I haven't found any way to make 'set' an instance of a typeclass. | ||||
Additional Information | Can anybody suggest a workaround for this issue? I would like to make 'set' a member of a typeclass. This isn't a problem for many other standard library types. For example, it doesn't affect 'list' because list is not defined as an equivalence type. It doesn't affect 'map' because map is not abstract (even though it doesn't appear in the documentation, map(K, V) is defined as equivalent to tree234(K, V) under a subsequent "interface" section, so it is not considered abstract). | ||||
Tags | No tags attached. | ||||
Relationships | |||||
Attached Files |
Notes | |||||
|
|||||
|
|
||||
|
|||||
|
|
||||
|
|||||
|
|
||||
|
|||||
|
|
||||
|
|||||
|
|
Issue History | |||||
Date Modified | Username | Field | Change | ||
---|---|---|---|---|---|
2011-02-03 17:45 | mgiuca | New Issue | |||
2011-02-04 01:07 | juliensf | Note Added: 0000304 | |||
2011-02-04 13:23 | mgiuca | Note Added: 0000305 | |||
2011-02-04 19:02 | juliensf | Note Added: 0000306 | |||
2011-02-04 19:03 | juliensf | Status | new => confirmed | ||
2011-02-07 10:47 | mgiuca | Note Added: 0000308 | |||
2011-02-16 14:00 | juliensf | Note Added: 0000313 |