On Fri, 2006-09-08 at 16:12 -0400, Peter Tanski wrote:
> On Sep 8, 2006, at 1:32 PM, skaller wrote:

> In Felix, typeclass should have function declarations:
> 
> // type classes embody rules; declarations, not definitions
> typeclass Eq[T] {     <--suggestion: no '=,' this is not assignment
>    add: t * t -> t;
>    sub: t * t -> t;   <-- no overriding, no virtual functions
>    ..
> }

The reason for = in some places is purely syntactic:
{ .. } is a valid expression. So for functions:

        fun f():int { ... }

is not a possible syntax, because it would mean:

        fun f(): _apply(int,{ ... })

that is, it would be an application. Since = is not allowed
in expressions .. I chose = to separate the return type from
the body:

        fun f():int = { ... }

If you think this is messy .. heck, I agree!

Note that in Felix executable expressions and type expressions
have the same syntax. This is sometimes inconvenient, for
example 

        a * b / c * d

means

        (a * b) / (c * d)

because * has a slightly higher precedence than /, the same
applies to + and -. For integers this never makes any difference.
For floats an modular arithmetic it might.

But the precedence is dictated by the type system:

        a * b * c * ( d * e )

is a tuple type with 4 components: tuple formation isn't
associative but an n-ary chain operator.

As to overriding and virtual functions: Haskell already
allows a default definition, doesn't it?

I used 'virtual' for a reason too: first, you can't just
write

        add: t * t -> t

because the user can't know if this is a curried procedure
or a function. The distinction is vital, so you need

        fun add: t * t -> t;

to say its a function. The problem is .. the syntax is
already defined, and means:

        fun add: t * t -> t = "add($1,$2)";

Perhaps I should change that .. but the short form is
very useful for binding libraries. So I threw in

        virtual fun: t * t -> t;

as a way to say "this is a signature".

        

> instance Eq[int] {    <--suggestion: no :public typeclass stuff
>     fun add: t * t -> t = x + y;
>     fun sub: t * t -> t = x - y;
> }

Again a minor problem. This notation:

        fun add: t * t -> t = "$1+$2";

specifies a C binding. And your notation doesn't declare
the symbols x or y .. :)


> // subsets
> typeclass Ord[T] <= Eq[T] {  <--suggestion: left-right s <= S
> ...
> }

Yeah, very unfortunate that. The logically correct notation
for x subset y is actually x => y not x <= y, because

        x => y means 'x implies y' 

;( Been toying with TeX operators ..

        x \subseteq y


> Getting type classes for Felix would be difficult, especially if you  
> want multi-parameter type classes.  As a start, you do unfortunately  
> have some reading to do.  After that we will have to modify the type  
> system to be able to type-check the typeclass. 

Why do we have to type check them?

-- 
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

Reply via email to