
Hello, why Haskell doesn't apply functions in preorder? e.g. f x = x max 1 f 2
2 max f 1 f 2 2 max max f 1 f 2 f 3 3 f f f f f f f f f f f 1 1
Thus you would need to put the arguments into brackets only when you want to partially apply that function. Is the current method more readable or error prone? King regards, Ford

If I understand correctly, you're asking why function application is left-associative rather than right-associative. With currying and first-class functions, right-association doesn't really work well. It's not obvious with a highly-constrained function like "max", but in practice most Haskell functions get composed and applied with other functions; real data only matters at the endpoints. For a reasonably simple example, consider the interaction between a couple of other Prelude functions: map :: (a -> b) -> [a] -> [b] const :: a -> b -> a Since (b -> a) is a type all by itself, it fits into a type variable for other functions; that is, "const" is an (a -> b) for the purposes of filling the first argument of "map". Applying this gets: map const :: [a] -> [b -> a] This takes a list of values, and returns a list of functions. So considering the type of "map const", which of the following behaviors seems more appropriate:
:t (map const) [1,2,3] map const [1,2,3] :: Num a => [b -> a]
:t map (const [1,2,3]) map (const [1,2,3]) :: Num a => [b] -> [[a]]
Haskell chooses the first option, because giving an argument [a] to an
expression whose type is currently [a] -> [b -> a] should probably return
[b -> a].
On Mon, Jul 4, 2016 at 12:43 AM, OxFord
Hello,
why Haskell doesn't apply functions in preorder? e.g.
f x = x
max 1 f 2
2 max f 1 f 2 2 max max f 1 f 2 f 3 3 f f f f f f f f f f f 1 1
Thus you would need to put the arguments into brackets only when you want to partially apply that function.
Is the current method more readable or error prone?
King regards,
Ford
_______________________________________________ Beginners mailing list Beginners@haskell.org http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
participants (2)
-
OxFord
-
Theodore Lief Gannon