caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
From: Martin Jambon <martin_jambon@emailuser.net>
To: Thomas Fischbacher <Thomas.Fischbacher@Physik.Uni-Muenchen.DE>
Cc: caml-list@inria.fr
Subject: Re: [Caml-list] What on earth is this?
Date: Fri, 11 Nov 2005 13:22:19 -0800 (PST)	[thread overview]
Message-ID: <Pine.LNX.4.63.0511111319290.5840@munge> (raw)
In-Reply-To: <Pine.LNX.4.61.0511112117490.6534@eiger.cip.physik.uni-muenchen.de>

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


  reply	other threads:[~2005-11-11 21:22 UTC|newest]

Thread overview: 3+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2005-11-11 20:18 Thomas Fischbacher
2005-11-11 21:22 ` Martin Jambon [this message]
2005-11-11 21:34 ` [Caml-list] " Thomas Fischbacher

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=Pine.LNX.4.63.0511111319290.5840@munge \
    --to=martin_jambon@emailuser.net \
    --cc=Thomas.Fischbacher@Physik.Uni-Muenchen.DE \
    --cc=caml-list@inria.fr \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).