Extra Considerations
Or, things I find helpful when I remember them.
Foldr and Foldl
foldris the constructor replacement function. Uses the incremental pattern. Lemmafoldlis the for loop. Can be implemented in terms offoldr. Uses the accumulator pattern.
Sections
Note Sections are the partial application of an operator.
map (+1) [1..5]
-- |
-- +--- adding one of the two parameters to the operator leaves it open.
-- This is the same as (\x -> x + 1)
-- Could also be (1+) since (\x -> 1 + x) is the same as (\x -> x + 1)
-- by commutativity.
--λ [2,3,4,5,6]
Caution! Keep in mind the commutativity of the operator! (e.g., (2^) and (^2) are not the same.)
-- A non-commutative example.
(2^) -- left section => (^) 2 => \x -> 2 ^ x
(^2) -- right section) => flip (^) 2 => \x -> x ^ 2
λ> (^2) <$> [3,5]
[9,25]
λ> (2^) <$> [3,5]
[8,32]
Fixity and Precedence
Passing an argument to a function has higher precedence than passing to an operator.
Infix operators have a "fixity" which determines how they favor precedence. <> has right fixity so something like "My name is" <> name <> "." is seen by the compiler as "My name is" <> (name <> ".").