4657Re: "ocaml_beginners":: mutually recursive definition of non-function values
- Oct 2, 2005On 10/1/05, Oliver Bandel <oliver@...-berlin.de> wrote:
> On Sat, Oct 01, 2005 at 12:06:01AM -0700, Radu Grigore wrote:These aren't syntatic constructs, they are semantic ones. And, IMO,
> > --- "Seth J. Fogarty" <sfogarty@...> wrote:
> > > Not if you know the semantics of let rec, and the way lists (or
> > > tuples) are allocated.
> > Nice explanation.
> I doubt it is.
> It explains what is going on internally with memory allocation and so on.
> But it does not explain why it is allowed to do such definitions in the
> If internal memory allocation is used as explanation for what
> syntactical/grammatical constructs are allowed in a high-level
> language like Oaml, then IMHO something goes wrong.
using the idea of 'locations' in semantics is perfectly valid. For
OCaml it is even necessary, to explain the difference between = and
> How long is that list?It has infinite length and extremely finite size (1 element).
> ...runs and runs and runs...No, the list is simply cyclic. It is a directed graph of three
> What's going on there?
> Does OCaml use lists that are too long as if they were
> lazy? Or does it turn them automagically into a lazy list?
elements which contains a cycle.
> Is there something of the FP-knowledge that I miss here?Nope.
> Can this behaviour (above example) be used on all types,Yes it can. You can create arbitrary cyclic lists, in fact.
> not only unit?
> Can this lead to undefined behaviour of the "high-level" language?No, the behavior is /very/ well defined. Just not terribly useful.
> If such constructs are leading to strange behaviour (or machine independent),Types are not values (sadly) in OCaml. But if you take an expression
> it maybe makes sense to disallow recursive values if not functions/types.
who's value is /not/ a location (integer, float, etc), you will find
that this behavior is not allowed.
let rec a = 1 + a
This kind of expression is not allowed as right-hand side of `let rec'
> But if one disallows that definition of recursive "simple"-values,Yes, this is frustrating. But this gap already exists in terms of
> there is a gap between first-class non-function values and first-class
equality. Type classes /might/ aleviate some of this.
> But if it is allowed, the language will be machine dependent,The language is /not/ machine dependent on this matter, as far as I know.
> and behaves strange here....?!
Seth Fogarty sfogarty@[gmail.com|rice.edu|livejournal]
Neep-neep at large AIM: Sorrath
"I know there are people in this world who do not love their fellow
human beings - and I hate people like that" --Tom Lehrer.
- << Previous post in topic Next post in topic >>