caml-list - the Caml user's mailing list
 help / color / mirror / Atom feed
* cost to let rec?
@ 2007-11-09 21:20 Ralph Douglass
  2007-11-09 21:28 ` [Caml-list] " Till Varoquaux
  2007-11-10 17:16 ` Andrej Bauer
  0 siblings, 2 replies; 4+ messages in thread
From: Ralph Douglass @ 2007-11-09 21:20 UTC (permalink / raw)
  To: Caml List

[-- Attachment #1: Type: text/plain, Size: 155 bytes --]

Is there any cost to defining a function with "let rec" instead of just
"let"?  A slightly longer compile time or something?  I'm just curious.

-- 
Ralph

[-- Attachment #2: Type: text/html, Size: 210 bytes --]

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

* Re: [Caml-list] cost to let rec?
  2007-11-09 21:20 cost to let rec? Ralph Douglass
@ 2007-11-09 21:28 ` Till Varoquaux
  2007-11-10 17:16 ` Andrej Bauer
  1 sibling, 0 replies; 4+ messages in thread
From: Till Varoquaux @ 2007-11-09 21:28 UTC (permalink / raw)
  To: Ralph Douglass; +Cc: Caml List

On Nov 9, 2007 4:20 PM, Ralph Douglass <ralph@grayskies.net> wrote:
> Is there any cost to defining a function with "let rec" instead of just
> "let"?  A slightly longer compile time or something?  I'm just curious.

Typechecking can indeed be longer, also reccursive functions are never
inlined (and, AFAIK, the compiler considers all function defined via
let rec as reccursive)

>
> --
> Ralph
> _______________________________________________
> 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
>
>


Till
-- 
http://till-varoquaux.blogspot.com/


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

* Re: [Caml-list] cost to let rec?
  2007-11-09 21:20 cost to let rec? Ralph Douglass
  2007-11-09 21:28 ` [Caml-list] " Till Varoquaux
@ 2007-11-10 17:16 ` Andrej Bauer
  2007-11-11  0:44   ` Arnaud Spiwack
  1 sibling, 1 reply; 4+ messages in thread
From: Andrej Bauer @ 2007-11-10 17:16 UTC (permalink / raw)
  To: Caml List

Ralph Douglass wrote:
> Is there any cost to defining a function with "let rec" instead of just
> "let"?  A slightly longer compile time or something?  I'm just curious.

The main cost of using "let rec" instead of "let" out of laziness or
"convenience" is time spent debugging the resulting bugs and the extra
time needed for software maintainance ("WTF did this Ralph guy write let
rec everywhere? My god he's totally incompetent and I have to clean
up."). This typically costs far, far more than any processor time you
might gain.

Source code is for humans.

Andrej


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

* Re: [Caml-list] cost to let rec?
  2007-11-10 17:16 ` Andrej Bauer
@ 2007-11-11  0:44   ` Arnaud Spiwack
  0 siblings, 0 replies; 4+ messages in thread
From: Arnaud Spiwack @ 2007-11-11  0:44 UTC (permalink / raw)
  Cc: Caml List

Yet another cost, but not too significant is redefinition.

Suppose you have a function "wrap" that does some safety stuff, on your 
argument "x". Well, then you want to name "warp x". One way of doing so 
is by hiding "x" so that you cannot access it :

let x = wrap x in ...

This does not work with "let rec" :

let rec x = wrap x in ...
"This kind of expression is not allowed as right-hand side of `let rec'"

Conclusion : "let rec" hides one variable from the scope of the body of 
the let, might be useful to have a "let" for these kind of things.


Arnaud Spiwack

Andrej Bauer a écrit :
> Ralph Douglass wrote:
>   
>> Is there any cost to defining a function with "let rec" instead of just
>> "let"?  A slightly longer compile time or something?  I'm just curious.
>>     
>
> The main cost of using "let rec" instead of "let" out of laziness or
> "convenience" is time spent debugging the resulting bugs and the extra
> time needed for software maintainance ("WTF did this Ralph guy write let
> rec everywhere? My god he's totally incompetent and I have to clean
> up."). This typically costs far, far more than any processor time you
> might gain.
>
> Source code is for humans.
>
> Andrej
>
> _______________________________________________
> 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] 4+ messages in thread

end of thread, other threads:[~2007-11-11  0:44 UTC | newest]

Thread overview: 4+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2007-11-09 21:20 cost to let rec? Ralph Douglass
2007-11-09 21:28 ` [Caml-list] " Till Varoquaux
2007-11-10 17:16 ` Andrej Bauer
2007-11-11  0:44   ` Arnaud Spiwack

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