On Tue, 2007-02-06 at 16:45 -0500, Jacques Carette wrote:

> 5) Take a good look at the "class aliases" 
> [http://repetae.net/john/recent/out/classalias.html].  There are some 
> horrible classes in Haskell (like Num) mostly because of these aliases 
> not existing.

Citing the note: 

"""given

 >  class Foo a where
 >    foo :: a -> Bool
 >    foo x = False
 >
 >  class Bar b where
 >    bar :: Int -> b -> [b]

We allow new constructs of this form:

 >  class alias FooBar a = (Foo a, Bar a) where
 >    foo = ...
"""

Well of course Felix can already do that:

typeclass FooBar[a] { inherit Foo[a]; inherit Bar[a]; }

However this isn't an alias:

"""The other thing is that one may declare instances of FooBar.

 > instance FooBar Int where
 >    foo x = x > 0
 >    bar n x = replicate n x

this expands to:

 > instance Foo Int where
 >    foo x = x > 0
 >
 > instance Bar Int where
 >    bar n x = replicate n x
"""

You can't do this in Felix .. and it is *already 
annoying*. Apart from which I'm really blown out
incremental instantiation works at all. I was very
surprised when it actually did .. :)

In Felix you actually have to instantiate
Foo, Bar AND FooBar (well you should have to!!):

typeclass FooBar[int] {} // required

even though FooBar has no non-inherited methods.
In fact it isn't clear this is enforced since
the actual instantiation dispatches on a per
method basis, and most of the front end (pre-
instantiation) checks have been turned off,
because they're way too hard to do correctly.

[The reason is they're working with *unbound* terms,
that is, terms containing raw string names, and it
is really hard to get complex logic to work with
such terms, compared to logic applied to the terms
after the string names have been replaced by globally
unique integer identifiers by lookup. I turned
most of the checks into warnings, and then turned
them off altogether because they have spurious diagnostics:
this has no effect on correctness, since the instantiator
can only select a proper method anyhow .. it just delays
diagnosis of a problem to later in the whole program
compilation .. possibly losing some of the context which
allows it to explain the issue to the end user]

Felix ALSO supports an entirely different mechanism
for composition which is very confusing to me!

You can ALSO write:

typeclass Ord[v with Eq[v] ] { ... }

This is quite different to

typeclass Ord[v] { inherit Eq[v]; }

The first case just applies a constraint to v ..
it doesn't make 'Ord' an extension of 'Eq', whereas
the latter does. When Ord is used in either case the
same constraint is actually applied, however!

The difference is not clear, however I found in
one case that a method definition (forget if it 
was in a typeclass or an instance) could not
do equality comparisons.

SO .. it may well be possible to fairly easily implement
'typeclass aliases' in Felix. There would be two ways
to do this which might work: an extra construction,
or, just allowing one to instantiate methods of
a base class such Eq in a derived class.

The latter might be a bit ugly:

instance Ord[int] { fun eq: .. }

ok .. so we actually provided an instance for Eq[int]
as well .. but you might 'grep' for instance Eq and wonder
what was going on!

An extra construction .. is an extra construction ;(




-- 
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
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to