I was asked by someone in #llvm if felix can do polymorphic recursion,
and I wasn't sure if we could. There's a paper about it:

http://www.church-project.org/reports/electronic/Hal+Kfo:BUCS-TR-2004-004.pdf

That has a simple example in SML:

//////////////////////////////////////////////////////////////////////
let val rec id = fn x => x
  and sumList = fn l => if (null l)
    then 0
    else (id (hd l)) + (sumList (id (tl l)))
in sumList [1,2,3] end
//////////////////////////////////////////////////////////////////////

That doesn't work. I tried to do this in felix but it errors out:

//////////////////////////////////////////////////////////////////////
open List;

fun id[T] (x:T): T => x;

fun sumList[T] (f:T*T->T, l:list[T]) : T =>
  match l with
  | Empty[T] => 0
  | Cons (?h, ?t) => f (h, sumList (f, t))
  endmatch
;

fun add_int (x:int, y:int) => x + y;

println $ sumList (the add_int, list(1,2,3));
//////////////////////////////////////////////////////////////////////

//////////////////////////////////////////////////////////////////////
Other exn = Flx_exceptions.Free_fixpoint(_)
CLIENT ERROR
[bind_exe: fun_return ] return of  (sumList_mh1198<1202>[<T5163>] ()):
fun return type:
int<2069>
must have same type as return expression:
<T5163>
In ./foo2.flx: line 5 col 1 to  line 12 col 1
 4:
 5: fun sumList[T] (f:T*T->T, l:list[T]) : T =>
 6:   //let ?x = id 5 in
 7:   //let ?y = id $ list(1,2,3) in
 8:   match l with
 9:   | Empty[T] => 0
10:   | Cons (?h, ?t) => f (h, sumList (f, t))
11:   endmatch
12: ;
13:
//////////////////////////////////////////////////////////////////////

Am I doing this wrong?

-------------------------------------------------------------------------
This SF.net email is sponsored by: Microsoft
Defy all challenges. Microsoft(R) Visual Studio 2008.
http://clk.atdmt.com/MRT/go/vse0120000070mrt/direct/01/
_______________________________________________
Felix-language mailing list
Felix-language@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/felix-language

Reply via email to