[
Home
]
[ Index:
by date
|
by threads
]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: | 2005-11-11 (21:22) |
From: | Martin Jambon <martin_jambon@e...> |
Subject: | Re: [Caml-list] What on earth is this? |
On Fri, 11 Nov 2005, Thomas Fischbacher wrote: > Maybe I just need a good night of sleep, maybe I overlooked something > really dumb and rather should have asked on the beginner's list. Anyway, > I find the behaviour demonstrated below quite confusing. Why don't the > definitions ###_v1 and ###_v2 work? Any idea, anyone? > let memoized ht f arg = ... ... > let rec mem_fibonacci_v1 = > let mem = Hashtbl.create 10 in > memoized mem > (fun n -> if n < 2 then 1 else mem_fibonacci_v1 (n-1) + > mem_fibonacci_v1 (n-2)) > ;; > (* Error: "This kind of expression is not allowed as right-hand side of `let rec'" *) > > let mem_fibonacci_v2 = > let mem = Hashtbl.create 10 in > let rec mf = > memoized mem > (fun n -> if n < 2 then 1 else (mf (n-1)) + (mf (n-2))) > in mf > ;; Almost there. This should work: let mem_fibonacci_v2 = let mem = Hashtbl.create 10 in let rec mf arg = memoized mem (fun n -> if n < 2 then 1 else (mf (n-1)) + (mf (n-2))) arg in mf Martin -- Martin Jambon, PhD - http://martin.jambon.free.fr Open Bioinformatics at http://wikiomics.org