Loading ...
Sorry, an error occurred while loading the content.

4657Re: "ocaml_beginners"::[] mutually recursive definition of non-function values

Expand Messages
  • Seth J. Fogarty
    Oct 2, 2005
    • 0 Attachment
      On 10/1/05, Oliver Bandel <oliver@...-berlin.de> wrote:
      > On Sat, Oct 01, 2005 at 12:06:01AM -0700, Radu Grigore wrote:
      > > --- "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
      > language.
      > 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.

      These aren't syntatic constructs, they are semantic ones. And, IMO,
      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...
      > 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?

      No, the list is simply cyclic. It is a directed graph of three
      elements which contains a cycle.

      > Is there something of the FP-knowledge that I miss here?


      > Can this behaviour (above example) be used on all types,
      > not only unit?

      Yes it can. You can create arbitrary cyclic lists, in fact.

      > 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),
      > it maybe makes sense to disallow recursive values if not functions/types.

      Types are not values (sadly) in OCaml. But if you take an expression
      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,
      > there is a gap between first-class non-function values and first-class
      > function-values.

      Yes, this is frustrating. But this gap already exists in terms of
      equality. Type classes /might/ aleviate some of this.

      > But if it is allowed, the language will be machine dependent,
      > and behaves strange here....?!

      The language is /not/ machine dependent on this matter, as far as I know.

      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.
    • Show all 15 messages in this topic