Why is a functional application selected as the default Haskell statement rather than composition?

Haskell syntax requires a relatively noisy f . g $ 3 f . g $ 3 compared to 3 gf , as in stack-oriented languages. What were the main design arguments for this choice?

+8
haskell
source share
4 answers

It can also be written f (g 3) .

Why is Haskell not a concatenative language?

Based on the Haskell Story , it has been influenced by many functional programs and lazy language experiments, including ML. In section 4, the syntax describes:

Currying

Following the tradition returning to Frege, a function of two arguments can be represented as a function of one argument, which itself returns a function of one argument. This tradition was honed by Moses Schonfinkel and Haskell Curry and became known as curry. Function assignment is indicated by matching and is associated with the left. Thus, fxy (fx) y analyzed. This leads to concise and powerful codes. For example, to compile each number in the list, write map square [1,2,3] , and in order to compose each number in the list of lists, write map (map square) [[1,2],[3]] . Haskell, like many other languages ​​based on the lambda calculus, supports both exact and unpainted definitions,

The concept of currying is so important for Haskell's semantics and the calculus of lambda at its core that any other way of layout interacts poorly with the language.

+12
source share
  • A stack-oriented style is not as much as a sequence function; 3 gf is such a language, rather f $ g $ 3 in Haskell. Of course, this is equivalent to f . g $ 3 f . g $ 3 , but it only works until you immediately apply the composition to some value. In Haskell, you very often compose functions just to pass them to some higher order combinator, or to make a trouble-free definition. In a stack-oriented language that requires some explicit block, only a statement is needed in Haskell . .
  • Usually you do not just bind atomic functions. Of course, you are not dealing with globally-named single-letter functions, so it’s tiny . or $ doesn't really make a dramatic difference in verbosity. And very often, as rmmh said, you associate partially applied functions, for example.

     main = interact $ unlines . take 10 . filter ((>20) . length) . lines 

    This is much more cumbersome without a cheap hard-linking application. In addition, it is very natural to have a separation . , to note that it was not immediately applied, but simply composed.

+11
source share

If you are interested in the story of Haskell, Hoodak, Hughes, Peyton Jones and Wadler, “Haskell's Story: Being Lazy with the Class” is the most famous article on this subject and worth reading.

It does not address your question directly, but it points to one very important fact: Haskell was created as a unifying compromise between a bunch of existing languages ​​from small teams. Quote 2.2 (The Tower of Babel):

As a result of all this activity, by the mid-1980s, a lot of researchers appeared, including authors who were very interested in both design methods and implementations for pure, lazy languages. In fact, many of us independently developed our own lazy languages ​​and were engaged in their creation of our own implementations. We wrote documents about our efforts in which we first had to describe our languages ​​before we could describe our implementation methods. The languages ​​that contributed to this lazy tower of Babel include:

  • Miranda [...]
  • Lazy ML (LML) [...]
  • Orwell [...]
  • Alfl [...]
  • Id [...]
  • Clear [...]
  • Ponder [...]
  • Daisy [...]

So the answer may simply be that Haskell copied this from its predecessor languages. And since a bunch of these languages, in turn, were founded or inspired by Lisp and ML, they can similarly copy it from them. So back to your question:

What were the main design arguments for this choice?

Most likely, there has never been a standing argument in favor of a choice. In any case, there are very few high-level languages ​​for stack-based design, and few know them.

+2
source share

My guess would be lambda calculus and utility (in real-world scenarios).

In terms of lambda, space is an application, and therefore it is more like people who know it.

In the most commonly used languages, the usual thing associated with a function is to use it. Haskell is not a stack-based language, so the choice was made there.

+1
source share

All Articles