caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* Re: The need to specify 'rec' in a recursive function defintion
@ 2010-02-11  6:48 oleg
  0 siblings, 0 replies; 6+ messages in thread
From: oleg @ 2010-02-11  6:48 UTC (permalink / raw)
  To: caml-list


Fortunately OCaml is (much more) than simply-typed lambda
calculus. Almost any feature of OCaml -- recursive data types,
recursive types, reference cells, mutable records, exceptions,
objects, recursive modules and polymorphic variants -- can be used to
express the fixpoint combinator. Sometimes there is more than one way
to use the same feature to express the fixpoint combinator. The more
and less known ways of expressing fix are collected in the following
document:

	http://okmij.org/ftp/ML/fixpoints.ml


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

* Re: The need to specify 'rec' in a recursive function defintion
  2010-02-15 20:36         ` Stefan Monnier
@ 2010-02-16 14:42           ` Stefan Monnier
  0 siblings, 0 replies; 6+ messages in thread
From: Stefan Monnier @ 2010-02-16 14:42 UTC (permalink / raw)
  To: caml-list

> It sure does, tho not with "fun" but only with "var" definitions.
                                                  ^^^
                                                  val

        Stefan "blush!"


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

* Re: The need to specify 'rec' in a recursive function defintion
  2010-02-15 17:33       ` [Caml-list] " Jon Harrop
@ 2010-02-15 20:36         ` Stefan Monnier
  2010-02-16 14:42           ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2010-02-15 20:36 UTC (permalink / raw)
  To: caml-list

>> Till Varoquaux had written:
>> > Let's make things clear here: the "rec" *really* is a feature;
>> Nobody said otherwise.  Eliminating the "rec" is also a feature.
>> Those two features are mostly incompatible, and many reasonable people
>> disagree on which one of the two is more important.
>> Stefan "who extensively used that feature in SML, but happens
>> to prefer the other feature nevertheless"
> Standard ML doesn't have the feature that Till described.

It sure does, tho not with "fun" but only with "var" definitions.


        Stefan


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

* Re: The need to specify 'rec' in a recursive function defintion
  2010-02-10 22:25   ` [Caml-list] " Till Varoquaux
@ 2010-02-15 15:46     ` Stefan Monnier
  2010-02-15 17:33       ` [Caml-list] " Jon Harrop
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2010-02-15 15:46 UTC (permalink / raw)
  To: caml-list

>>> Wouldn't one of way of detecting a recursive function would be to see
>>> if the indeed the function calls itself?
>> That's what Haskell does, yes.
> Let's make things clear here: the "rec" *really* is a feature;

Nobody said otherwise.  Eliminating the "rec" is also a feature.
Those two features are mostly incompatible, and many reasonable people
disagree on which one of the two is more important.


        Stefan "who extensively used that feature in SML, but happens
                to prefer the other feature nevertheless"


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

* Re: The need to specify 'rec' in a recursive function defintion
  2010-02-09 20:50 Saptarshi Guha
@ 2010-02-10 22:01 ` Stefan Monnier
  2010-02-10 22:25   ` [Caml-list] " Till Varoquaux
  0 siblings, 1 reply; 6+ messages in thread
From: Stefan Monnier @ 2010-02-10 22:01 UTC (permalink / raw)
  To: caml-list

> Wouldn't one of way of detecting a recursive function would be to see
> if the indeed the function calls itself?

That's what Haskell does, yes.


        Stefan


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

* The need to specify 'rec' in a recursive function defintion
@ 2010-02-09 20:50 Saptarshi Guha
  2010-02-10 22:01 ` Stefan Monnier
  0 siblings, 1 reply; 6+ messages in thread
From: Saptarshi Guha @ 2010-02-09 20:50 UTC (permalink / raw)
  To: caml-list

Hello,
 I was wondering why recursive functions need to be specified with
"rec". According to Practical Ocaml, to "inform the compiler that the function
exists". But when entering the function definition, can't the compiler note that
the function is being defined so that when it sees the function calling itself,
it wont say "Unbound value f"?

How is the knowledge of a function being rec taken advantage of (in
ocaml) as opposed to other languages
(leaving aside tail call optimization).

Wouldn't one of way of detecting a recursive function would be to see
if the indeed the function calls itself?

These are very much beginners' questions.
Thank you
Saptarshi


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

end of thread, other threads:[~2010-02-16 14:42 UTC | newest]

Thread overview: 6+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2010-02-11  6:48 The need to specify 'rec' in a recursive function defintion oleg
  -- strict thread matches above, loose matches on Subject: below --
2010-02-09 20:50 Saptarshi Guha
2010-02-10 22:01 ` Stefan Monnier
2010-02-10 22:25   ` [Caml-list] " Till Varoquaux
2010-02-15 15:46     ` Stefan Monnier
2010-02-15 17:33       ` [Caml-list] " Jon Harrop
2010-02-15 20:36         ` Stefan Monnier
2010-02-16 14:42           ` Stefan Monnier

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