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

Which direction should function arrows point?

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