Version française
Home     About     Download     Resources     Contact us    
Browse thread
[Caml-list] Style question: excessive currying confusion?
[ Home ] [ Index: by date | by threads ]
[ Search: ]

[ Message by date: previous | next ] [ Message in thread: previous | next ] [ Thread: previous | next ]
Date: -- (:)
From: Brady Montz <bradym@b...>
Subject: [Caml-list] Style question: excessive currying confusion?
[ I posted this to comp.lang.ml a few weeks ago, before I found this
  list ]

Howdy ya'll. I'm a long time C and lisp programmer who's taken on
learning CAML for real. I played with ML a bit a few years ago in grad
school.

So I'm working through lots of CAML code now, and I find code which
"excessively" uses currying to be a bit hard to read. I'm curious if
this gets better with practice, and if anyone has some good style
rules about this.

So, here's an extremely simple example:

let fun1 x y z =
  [ x; y; z];;

let fun2 x = 
  fun1 (x + 1);;

(* alternative implementation of fun2 *)
let fun3 x y z = 
  fun1 (x + 1) y z;;

Suppose I'm reading through someone else's program, and I come across
the definition for fun2, and I want to know what it does. I can't even
know how many parameters fun2 takes until I refer to the definition of
fun1. The confusion is worst when I don't even know I'm confused about
the number of args fun2 can take.

Now, in most cases I've hit the confusion would have been much
lessened with proper function naming and commenting, but not always. 

Now, on the other hand, there are times when currying is obviously
great. For example, if it is really important to me that fun2 always
have a similar signature to fun1, then this seems fine to me. Also,
there is benefit to keeping the code succinct.

So, anyhoo, if anyone has helpful advise to this ML newbie, I'd much
appreciate it. 

-- 
 Brady Montz
 bradym@balestra.org
-------------------
Bug reports: http://caml.inria.fr/bin/caml-bugs  FAQ: http://caml.inria.fr/FAQ/
To unsubscribe, mail caml-list-request@inria.fr  Archives: http://caml.inria.fr