skaller wrote:

> [EMAIL PROTECTED]:/work/felix/svn/felix/felix/trunk$ f er3
> 5
> (1, (2, (3, (4, ()))))
>
> Try svn update?

That one worked as well! Now for the grand finale, using a typeclass 
without opening the module:


#import <flx.flxh>

open List;

typeclass Str[T] {
  virtual fun str2: T->string;
}

module Foo {
  instance Str[int] {
    fun str2 (x:int):string => str x;
  }

  fun foo[T with Str[T]] (x:T):string => str2 x;

  fun foo[T with Str[T]] (x:list[T]):string =>
    match x with
    | Empty[T] => "()"
    | Cons(?h, ?t) => "(" + (str2 h) + ", " + (foo t) + ")"
    endmatch
  ;
}

print$ Foo::foo 5; endl;
print$ Foo::foo$ list(1,2,3,4); endl;


Prints:

CLIENT ERROR
[lookup_name_in_env]: Name '_inst_Str' not found in environment (depth 2)
In foo.flx: line 14, cols 18 to 24
13:
14:   fun foo[T with Str[T]] (x:T):string => str2 x;
                     *******
15:


Once we have this working, we can start using type classes in the stdlib :)

-e

-------------------------------------------------------------------------
Take Surveys. Earn Cash. Influence the Future of IT
Join SourceForge.net's Techsay panel and you'll get the chance to share your
opinions on IT & business topics through brief surveys -- and earn cash
http://www.techsay.com/default.php?page=join.php&p=sourceforge&CID=DEVDEV
_______________________________________________
Felix-language mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to