[erlang-questions] erlang improvement - objective c (or smalltalk) syntax

Richard O'Keefe <>
Fri Jun 5 08:28:53 CEST 2009


On 5 Jun 2009, at 2:32 am, Daniel Goertzen wrote:
> To go on a bit of a tangent, an idea from a language I saw years ago  
> (can't
> remember what it was called) is that all functions take only 1  
> parameter,
> but that parameter is understood to be a tuple.  You didn't have to
> explicitly pack and unpack them; it all happened automatically  
> behind the
> scenes.  I think this is pretty neat, because tuples and function  
> parameters
> are already quite similar, and this idea unifies the concepts.   
> Python also
> has convenient ways of interchanging parameter lists, tuples, and
> dictionaries.

For an imperative language that uses this idea, see Mesa.
Mesa functions take a tuple of arguments and return a tuple of results.
Many functional languages have the idea that a function has one
argument and one result, see Clean, Haskell, SML, and O'CAML.
Clean and Haskell style prefers to treat a function with two
arguments as a function that returns a function, so
	(+) :: Num a => a -> (a -> a)
"+ can be used with any numeric type a; pass it an argument of
  type a and you get another function back, give _that_ one an
  argument of type a, and you'll get an a back."
SML and O'CAML prefer passing a tuple.  However, SML compilers work
very hard to try to ensure that the tuple is never actually created.
For a crude idea of what might be done, consider
	fun f(x,y) = ...whatever...
implemented as

	f tuple = f' (fst tuple) (snd tuple)
	f' x y = ...whatever...

and whenever you see a call f(a, b) you generate a call to f' a b
instead.  Now generalise, and you'll have what they do.

The thing is that you really do NOT want to actually *allocate* all
these tuples.  ML compilers are helped in all of this by the
obligatory strong type system.




More information about the erlang-questions mailing list