#+Title: Today * Kernel #+BEGIN_SRC C int x; // fine; statement if (1 < 2) x = 3; else x = 5; // not; expression x = if (1 < 2) 3 else 5; // instead you must remember x = (1 < 2)? 3 : 5; // no else! if (1 < 2) printf("noice"); // Often #define skip // This does nothing if B then S₁; ≈ if B then S₁ else skip; // What do⁉ int y = if (9 < 2) then 3; // C# may do something like this // using the “default” keyword if B then S₁; ≈ if B then S₁ else default(T); ⇐ provided S₁ is of type T #+END_SRC Likewise in Haskell using ~mempty~. * Monoids A Monoid is a set C with a binary operation ⊕ and an element ε such that + Identity: x ⊕ ε ≈ x ≈ ε ⊕ x + Associtivity: x ⊕ y ⊕ z is “unambiguous” - Exercise: What does this mean? Prime example: + Set: Programs + Operation: Sequencing + Element: skip + S₁ ⨾ S₂ ⨾ S₃ with no trouble #+BEGIN_SRC haskell ➪ Do Nothing: skip ➪ Sequencing: S₁⨾S₂ “do S₁ then do S₂” #+END_SRC + Mother of computation: The Fold! - Look it up! + Filter, map, fold - Exercise: Define sum, max, min, mult, factorial, map, filter, reverse in terms of fold. * Oz (message-box "woah") #+BEGIN_SRC oz {Browse 'noice'} {Browse 'again'} #+END_SRC #+BEGIN_SRC oz {Show "woah"} {Show 'explicitly me'} #+END_SRC #+RESULTS: