wiki:FirstPrinciples/Composability

Composability

Everything composes - particles (or shall we say localized energy) into atoms, atoms into molecules, molecules into amino acids, aminoacidos into proteins and enzymes, etc.

To make sure that the compositions are consistent we need Types

Function composition

For functions composition is just nesting.

f . g  =  \x -> f (g x)

Nesting of functions is the only way to establish (ensure) the evaluation order in a pure-functional lazy language.

Currying

Currying is related to Nesting

\x -> \y -> x + y

is an implicit function composition.

No wonder, Monad composition

sequence []      =  return []
sequence (a:as)  =  do 
                       x  <- a
                       xs <- sequence as 
                       return (x:xs)

desugars into nothing but a function composition.

sequence []      =  return []
sequence (a:as)  =  a >>= \x ->
                          sequence as >>= \xs ->
                                          return (x:xs)
Last modified 17 months ago Last modified on Nov 15, 2018, 10:05:53 AM
Note: See TracWiki for help on using the wiki.