You need to say 'rec' after 'let'.

By on 1/16/2011 9:20 AM ()

But they don't refer to each other.
Why would compiler force me to do that?
OCaml compiler compiles it without any complaints.

By on 1/17/2011 5:50 AM ()

Or, since the bindings aren't recursive, just use 'let' again instead of 'and'.

By on 1/16/2011 12:35 PM ()

Yes, I'm aware of this "fix", but I don't get why is it required in the first place.
Would it break something (type inference,...) if such a definition was allowed?

By on 1/17/2011 5:52 AM ()

The 'rec' changes the semantics and warns you that this/future identifiers will be in scope in the body. A la

[link:stackoverflow.com]

You could allow 'let...and' to mean 'let rec...and' but then if a human is scanning the code, and the 'let' is at the top of the screen but the function body is long and the 'and' is on the next page of code, you can't tell if the function name is in scope or not without scrolling down.

By on 1/17/2011 10:53 AM ()

I use 'let...and' no to mean 'let rec...and', but quite the opposite - to emphasize they are at the same level in scope and don't refer to each other.

Let's say we have:

1
2
let a = 1
let b = 2

Someone might read it like 'a' is used in 'b' which is not the case and doesn't make a lot of sense in this piece of code.
So to make it clear that both names don't depend one on another 'and' could be used.

As far as I can see it's a common practise in OCaml.

By on 1/17/2011 4:19 PM ()

Aaaah, I was completely oblivious to this use/meaning in OCaml.

Yes, that is interesting. The only thing like it in F# would be e.g.

1
    let a, b = 1, 2

but for the cases you are talking about in practice, probably just say 'let ... let' (and cope with 'a' being in scope for 'b').

By on 1/17/2011 4:47 PM ()

Cool, so we are on the same page.
I guess it makes OCaml code a bit less portable than it could be without anything in return.
Are you aware of any benefits of such a restriction?

By on 1/18/2011 5:21 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper