[nem-bug] [Nemerle 0000646]: Clarification req. about typing system
feedback at nemerle.org
feedback at nemerle.org
Tue Apr 4 01:45:06 CEST 2006
A NOTE has been added to this issue.
======================================================================
<http://nemerle.org/bugs/view.php?id=646>
======================================================================
Reported By: SeamusL
Assigned To:
======================================================================
Project: Nemerle
Issue ID: 646
Category: Compiler
Reproducibility: always
Severity: minor
Priority: normal
Status: new
======================================================================
Date Submitted: 04-03-2006 21:48 CEST
Last Modified: 04-04-2006 01:45 CEST
======================================================================
Summary: Clarification req. about typing system
Description:
Where 'a : 'b, can it follow that Iface['a] : Iface['b]?
I can't implement several instances of a generic interface. Is this a
feature or not working or am I just doing things incorrectly? I would like
to implement an interface for several, but not all, subtypes of a base
type.
See attached commented code for my gripes.
Sorry if this is mis-classified. I am unsure about the nature of the
problems I face (features, bugs, my own stupidity.)
======================================================================
----------------------------------------------------------------------
nazgul - 04-03-06 22:20
----------------------------------------------------------------------
There are several issues:
1) you say that compiler did not infer IComparable interface for
DefContainsImpl, this is not true, as you can see in my attached example.
Probably the problem was the need for upcast to IComparable, which is
needed for type parameters (and explicitly implemented interfaces) - it
statically typesafe, but needed in Nemerle and C#.
2) the IComparable, which you added to DefContainsImpl causes for ugly
problems with compiler:
- the internal compiler error you observed, which is of course a bug
- CheckSTV, I guess it is a known bug, the message is very unclear, but
means that default type used (object) does not satisfy 'a : IComparable
['a]
- the 'typing constraint on 'a not satisfied, upon instantiation of
DefContainsImpl', which is a little bit unclear, but true - Thing does not
implement IComparable [Thing] (it just derives implementation of
IComparable [Entity])
3) the last obstacle is by design at the moment - the limitation (which is
not present in C#) is quite important for type inference algorithm used in
Nemerle compiler, because it simplifies reasoning about how given type
implements some interface. I guess changing this is possible, but Michal
who designed the alorithm would know better
----------------------------------------------------------------------
SeamusL - 04-04-06 01:45
----------------------------------------------------------------------
Thank you for clearing some of this up for me. It is unfortunate that the
side-effect is that I can't, as I'd hoped, write the following class, due
to the possible upcasting required, but I can certainly work around it.
The bit I do miss is the use of multiple interface instances, because I
can see copy-and-paste code in my near future, but I can see that this
could cause many cases which would effectively break type inference.
Possibly this should be documented (I haven't seen it mentioned); maybe
under "Grok Parametric Polymorphism" or "Grok OOP", though that doesn't
quite seem the right place, since it's a side issue.
public class DefContainsImpl['a] : Contains['a]
where 'a : Entity {
el : 'a;
_lst : Set['a]; // This must be Set[Entity], or possibly list['a]
foo (x : 'a) : void {
_ = (el : IComparable [Entity]).CompareTo (x);
}
}
Issue History
Date Modified Username Field Change
======================================================================
04-03-06 21:48 SeamusL New Issue
04-03-06 21:48 SeamusL File Added: test1.n
04-03-06 22:10 nazgul File Added: t.n
04-03-06 22:20 nazgul Note Added: 0001152
04-04-06 01:45 SeamusL Note Added: 0001160
======================================================================
More information about the bugs
mailing list