* 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
* 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
* 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
* Re: [Caml-list] Re: The need to specify 'rec' in a recursive function defintion
2010-02-10 22:01 ` Stefan Monnier
@ 2010-02-10 22:25 ` Till Varoquaux
2010-02-15 15:46 ` Stefan Monnier
0 siblings, 1 reply; 6+ messages in thread
From: Till Varoquaux @ 2010-02-10 22:25 UTC (permalink / raw)
To: caml-list
On Wed, Feb 10, 2010 at 5:01 PM, Stefan Monnier
<monnier@iro.umontreal.ca> wrote:
>> 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; it is
very convenient to reuse the same identifier to express something in
the process of being built (e.g. something going through a pipeline).
For instance:
let g () =
let f s =
if !debug then
Printf.printf "f is called with value: %s\n%!" s
f s
in
.......
Some (including me) would even argue that it is sad that type
definitions don't use "rec".
Till
> Stefan
>
> _______________________________________________
> Caml-list mailing list. Subscription management:
> http://yquem.inria.fr/cgi-bin/mailman/listinfo/caml-list
> Archives: http://caml.inria.fr
> Beginner's list: http://groups.yahoo.com/group/ocaml_beginners
> Bug reports: http://caml.inria.fr/bin/caml-bugs
>
^ 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: [Caml-list] Re: The need to specify 'rec' in a recursive function defintion
2010-02-15 15:46 ` Stefan Monnier
@ 2010-02-15 17:33 ` Jon Harrop
2010-02-15 20:36 ` Stefan Monnier
0 siblings, 1 reply; 6+ messages in thread
From: Jon Harrop @ 2010-02-15 17:33 UTC (permalink / raw)
To: caml-list
On Monday 15 February 2010 15:46:58 Stefan Monnier wrote:
> 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.
--
Dr Jon Harrop, Flying Frog Consultancy Ltd.
http://www.ffconsultancy.com/?e
^ 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
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