Mailing list for all users of the OCaml language and system.
 help / color / mirror / Atom feed
From: "SooHyoung Oh" <shoh@duonix.com>
To: "Caml-List" <caml-list@inria.fr>
Subject: [Caml-list] fib with lazy list
Date: Wed, 23 Apr 2003 19:53:28 +0900	[thread overview]
Message-ID: <003901c30986$92677ff0$fe00a8c0@hama> (raw)

I'm trying to implement "fib" function with lazy list.
I met the error with message:
    File "eg1.ml", line 19, characters 19-35:
    This kind of expression is not allowed as right-hand side of `let rec'

Can anyone solve this problem?

------- source begin ---------
type 'a lzlist = LzCons of 'a * 'a lzlist Lazy.t;;
let rec forever n = LzCons (n, lazy (forever n));;
let rec lzlist f n = LzCons (n, lazy (lzlist f (f n)));;
let hd (LzCons (n, l)) = n;;
let tl (LzCons (n, l)) = Lazy.force l;;
let from n =
    let add1 m = m + 1 in
    lzlist add1 n
;;
let rec map f lls =
    LzCons (f (hd lls), lazy (map f (tl lls)))
;;
let rec nth lls n =
    match n with
    | 0 -> hd lls
    | n -> nth (tl lls) (n-1)
;;

let rec fib_list = map fib (from 0)    (* ERROR *)
and fib n =
    match n with
    | 1 -> 1
    | n -> nth fib_list (n-1) + nth fib_list (n-2)
;;

let main = fib 5;;
-------------- end of source ------------------
---
SooHyoung Oh

-------------------
To unsubscribe, mail caml-list-request@inria.fr Archives: http://caml.inria.fr
Bug reports: http://caml.inria.fr/bin/caml-bugs FAQ: http://caml.inria.fr/FAQ/
Beginner's list: http://groups.yahoo.com/group/ocaml_beginners


             reply	other threads:[~2003-04-23 10:53 UTC|newest]

Thread overview: 4+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2003-04-23 10:53 SooHyoung Oh [this message]
2003-04-23 12:09 ` sebastien FURIC
2003-04-23 12:24   ` sebastien FURIC
2003-04-23 12:20 ` Michel Quercia

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='003901c30986$92677ff0$fe00a8c0@hama' \
    --to=shoh@duonix.com \
    --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