On Fri, 2006-09-08 at 20:35 -0400, Peter Tanski wrote:
> same :: (Eq a) => a -> a -> Bool
I think I know how to implement the whole thing now!
It's quite cute, I have to say. Initial implementation
will only allow typeclasses with independent (unconstrained)
variables, no 'inheritance'.
It looks like the syntax:
[r,s where Ord[r]]
has some problems. The idea here was you could write
[r,s where is_function r]
that is, you could add constraints on the types r,s.
Typeclasses do that. However the constraints don't
do anything else. Typeclasses DO do something else:
they introduce extra overloads into the scope
of the function (namely, the ones in the typeclass,
with appropriate substitutions).
When lookup selects one of these overloads, then
we have the typeclass's function as the function's
alpha-converted name, but we have to record the
substitutions too. Luckily Felix already knows exactly
how to do that: it's just another polymorphic function
binding.
When we come to instantiate, we get a complete
substitution eliminating all the type variables.
however instead of elaborating the function,
which we can't do because it has no body, it's
just a signature, we have to lookup the table
of instances for that function and typevariable
substitution, and use that.
Luckily, this doesn't seem to require any searching,
because somewhere alone the line the instance
is passed IN (it enters at the top level call
and flows through the polymorphic routines).
Anyhow it seems I need better than
[r,s where Ord[r]]
In particular, here Ord is NOT actually a checkable constraint.
The only checking is done with top level calls, that is,
when you'd have (using the same lame syntax):
[where Ord[int]]
in which case the check is to search for an instance of
Ord with argument int.
--
John Skaller <skaller at users dot sf dot net>
Felix, successor to C++: http://felix.sf.net
-------------------------------------------------------------------------
Using Tomcat but need to do more? Need to support web services, security?
Get stuff done quickly with pre-integrated technology to make your job easier
Download IBM WebSphere Application Server v.1.0.1 based on Apache Geronimo
http://sel.as-us.falkag.net/sel?cmd=lnk&kid=120709&bid=263057&dat=121642
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language