On 01/05/11 08:14, Kerneltrap wrote:
> Hi OCaml'ers.
>
> Why is this
> let x = 1 and y = x in y;;
> typed as
> (int -> int) -> int = <fun>
> ?
> I'd expect it to have type of int and be evaluated to 1.
That's because the x in "y = x" is a value which happens to be defined
previously in your toplevel session. The new x is not visible yet.
Here is what you would normally get:
$ ocaml
Objective Caml version 3.12.0
# let x = 1 and y = x in y;;
Warning 26: unused variable x.
Error: Unbound value x
> How is it different to
> let x = 1 in let y = x in y;;
> which meets my typing expectations?
This does what you intend to do: defining x and making it visible in
what follows.
Martin
--
You received this message because you are subscribed to the Google Groups
"ocaml-developer" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/ocaml-developer?hl=en
For other OCaml forums, see http://caml.inria.fr/resources/forums.en.html