Browse thread
[Caml-list] strange behaviour of ocamldoc
[
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: | -- (:) |
| From: | Brian Hurt <bhurt@s...> |
| Subject: | Re: [Caml-list] Confused |
On Wed, 15 Sep 2004, Jon Harrop wrote:
>
> How come this works:
>
> # let rec build = function 0 -> [] | n -> 1e-6 :: build (n-1);;
> val build : int -> float list = <fun>
> # let test = 1. :: build 1000;;
> val test : float list = ...
>
> But this does not:
>
> # let rec build = function 0 -> [] | n -> 1e-6 :: build (n-1) in
> let test = 1. :: build 1000;;
> Syntax error
What you want to do is:
let test =
let rec build = funcion 0 -> [] | n -> 1e-6 :: build (n-1) in
1. :: build 1000
;;
"let var = expression" is not, itself, and expression. It's a statement.
Ocaml does, in fact, have statements and not just expressions. The let/in
construct is: "let var = expression in expression" is an expression- but
it requires the stuff to the right of the 'in' keyword to also be an
expression. This means that it can be another let/in expression, but not
statements like "let var = expression".
The solution, then, is to move the let/in definition down into the
expression part of the statement- i.e., after the equals sign. Thus my
counter-example.
> Am I being stupid?
No- just confused on a subtle point of Ocaml syntax.
--
"Usenet is like a herd of performing elephants with diarrhea -- massive,
difficult to redirect, awe-inspiring, entertaining, and a source of
mind-boggling amounts of excrement when you least expect it."
- Gene Spafford
Brian
-------------------
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