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

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

Expand Messages
  • Oliver Bandel
    Oct 1, 2005
    • 0 Attachment
      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.

      =============================================================
      # let rec cycled_list = () :: cycled_list;;
      val cycled_list : unit list =
      [(); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); ();
      (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); ();
      (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); ();
      (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); ();
      (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); ();
      (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); ();
      (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); ();
      (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); ();
      (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); ();
      (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); ();
      (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); ();
      (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); ();
      (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); ();
      (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); ();
      (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); ();
      (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); (); ();
      (); (); (); (); (); (); (); (); (); (); (); ...]
      #
      =============================================================




      How long is that list?

      =============================================================
      # let x = let rec cycled_list = () :: cycled_list in List.length cycled_list;;

      =============================================================

      ...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?


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

      Can this behaviour (above example) be used on all types,
      not only unit? If not: why does Ocaml as a high-level language
      (not as a thingy with a certain implementation and running on
      an operating system with certain memory allocation mechanisms)
      behave differently for these or that types, when using a
      "common", allowed syntactical construct?!

      Can this lead to undefined behaviour of the "high-level" language?

      If such constructs are leading to strange behaviour (or machine independent),
      it maybe makes sense to disallow recursive values if not functions/types.
      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.

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

      So, what can be said about THIS question?

      Ciao,
      Oliver
    • Show all 15 messages in this topic