caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re:  Restrictions of let rec
@ 1998-03-09 17:36 Damien Doligez
  0 siblings, 0 replies; 2+ messages in thread
From: Damien Doligez @ 1998-03-09 17:36 UTC (permalink / raw)
  To: rossberg; +Cc: caml-list

>From: Andreas Rossberg <rossberg@ips.cs.tu-bs.de>
[...]
>  let rec f = f' some_defaul_arg
>  and f' v = function ... -> ...f' v' x... | ... -> ...f y... | ...
>
>The compiler argues that "this kind of expression is not allowed with
>`let rec'", probably because the RHS of f is neither an abstraction nor
>a constructor application nor does f appear in it.
                           ^^^^^^^^^^^^^^^^^^^^^^^

This last item is irrelevant.  The RHS has to be a function
abstration, a constructor, an array, or a record.  More precisely,
every RHS of a let rec must be a value and not a variable. <<value>>
is defined as a subclass of expression:

value :
  | value-path
  | constant
  | ( value )
  | begin value end
  | ( value : typexpr )
  | value, value {, value}
  | ncconstr value
  | value :: value
  | [ value {; value} ]
  | [| value {; value} |]
  | { label = value {; label = value} }
  | function pattern-matching
  | fun multiple-matching
  | let [rec] let-binding {and let-binding} in value

Note that "pattern-matching" and "multiple-matching" in the above are
the real thing, which may contain arbitrary expressions.


>I know it's easy to avoid this by doing eta conversion, but I don't see
>the point in disallowing such definitions. What's the rationale?

In short, we want to avoid run-time errors.


>Maybe
>it's an oversight and the compiler should actually check whether f
>appears on _any_ RHS of the let rec?

I don't understand this remark, since f does appear on the RHS of f'
in your example.  Anyway, when f does not appear in any RHS, then its
definition is not really recursive, so you shouldn't include f in the
let rec (unless you're trying to obfuscate your code).

-- Damien





^ permalink raw reply	[flat|nested] 2+ messages in thread

* Restrictions of let rec
@ 1998-03-09 16:15 Andreas Rossberg
  0 siblings, 0 replies; 2+ messages in thread
From: Andreas Rossberg @ 1998-03-09 16:15 UTC (permalink / raw)
  To: caml-list

Hello,


working with OCaml I recently found the following (syntactic?)
restriction quite odd. Consider:

  let rec f = f' some_defaul_arg
  and f' v = function ... -> ...f' v' x... | ... -> ...f y... | ...

The compiler argues that "this kind of expression is not allowed with
`let rec'", probably because the RHS of f is neither an abstraction nor
a constructor application nor does f appear in it.

I know it's easy to avoid this by doing eta conversion, but I don't see
the point in disallowing such definitions. What's the rationale? Maybe
it's an oversight and the compiler should actually check whether f
appears on _any_ RHS of the let rec?


	- Andreas





^ permalink raw reply	[flat|nested] 2+ messages in thread

end of thread, other threads:[~1998-03-10 18:40 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
1998-03-09 17:36 Restrictions of let rec Damien Doligez
  -- strict thread matches above, loose matches on Subject: below --
1998-03-09 16:15 Andreas Rossberg

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).