Version française
Home     About     Download     Resources     Contact us    
Browse thread
explict vs inexplicit constant parameters
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Julian Assange <proff@i...>
Subject: explict vs inexplicit constant parameters

I often use the following:

let findpair e l =
  let rec find = function
    | [] -> None
    | (a,b)::tl -> if a = e then Some b else findpair tl 
  in
  find l

instead of:

let findpair e l =
  let rec find e = function
    | [] -> None
    | (a,b)::tl -> if a = e then Some b else findpair e tl 
  in
  find e l

Is ocaml able to generate faster code for the former?

Stylistically, I'm not sure whether these constructs are a good thing
or not. Symbolic brevity makes makes it easier to read for small
contexts.  On the other hand for larger contexts, the de-localisation
of variables makes the whole thing harder to follow and dangerous to
re-order.

Cheers,
Julian.