The author of the CT/math book I'm reading (Paolo ...
# of-functional-programming
d
The author of the CT/math book I'm reading (Paolo Aluffi) suggested that if functions defs put output first (
f : B <- A
instead of
f : A -> B
) then function composition like
f . g
would make more sense. Then a couple chapters later he goes on to say that writing
(x)f
instead of
f(x)
would make
(f.g)(x)
be
((x)g)f
(or even maybe
xgf
) Both are nice suggestions, but the mix really does hurt my head
s
If you read older algebra books, people actually do this. I think herstein's book does it. The context switching I think is why people have mostly settled on one notation
d
De Bruijn Notation is a variant notation for lambda calculus where you write
(x)f
to call a function. The wikipedia page describes how this simplifies the algebraic manipulation of lambda terms, and makes certain proofs easier. https://en.wikipedia.org/wiki/De_Bruijn_notation
F# has an infix function call operator where
x |> f
means
f x
, and an infix function composition operator where
f >> g
is the same as
g . f
in Haskell. This design has become popular, and has been widely copied by newer functional languages.
👍 2
e
I think another perspective is evaluation order / dominance of expressions. For example, in a lazy language like Haskell, an expression like
f x
- is "dominated" by
f
which may choose to evaluate or not evaluate
x
at all, and in any case
f
and its application are evaluated first. So it makes sense to see things ordered by their importance:
f (g (h x)).
In an eager language, it's nicer to see things read by their evaluation order:
x |> g |> f
(though
f
or
g
as function yielding expressions are actually be evaluated first, their application is evaluated later).
👍 2
Another perspective on whether we should write:
f : B <- A
or
f : A -> B
is analogy to arithmetic.
A -> B
is
B ^ A
(B raised to the power of A). So making the notations align up could be nice
😄 1
w
The Forth is strong.