[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

RE: Which direction should function arrows point?



Lambert Meertens and other Squillores have been using the arrow in the
reverse direction for a long time, and for essentially the reason you
mention. For instance check out http://citeseer.nj.nec.com/247990.html.

Hope this helps,

Erik Meijer

-----Original Message-----
From: Neel Krishnaswami [mailto:neelk@alum.mit.edu] 
Sent: Monday, March 31, 2003 3:50 PM
To: ll1-discuss@ai.mit.edu


Here's a critical, burning language design question. Why do people
write function arrows from left to right (eg, "int -> string")
rather than right to left ("string <- int")?

The reason I ask is that composition is much more readable when you
put the result on the left. Take the type of the compose function

fun compose(f, g) {
  fun(x) { f(g(x)) }
}

The conventional spelling of its type is:

  (a -> b, c -> a) -> (c -> b)
  ^^^          ^^^
Notice how the 'a' expression is separated, so that you can no longer
clearly see the flow of data. 

  (a -> b, c -> a) -> (c -> b)
        ^^^^           ^^^^^^
See also that the order of the types in the arguments is transposed
from how they appears in the return value.

Compare this with the right-to-left version:

  (b <- c) <- (b <- a, a <- c)

Both of those defects have been fixed in this version. The 'a's appear
next to each other, so that they are easy to visually "cancel out",
and the order of the types in the return value matches the order in
the argument. 

However, I haven't seen this notation in any other programming
language, and I wonder if there is a deeper reason for the standard
convention that I have missed. 

-- 
Neel Krishnaswami
neelk@alum.mit.edu