Hideaki Kawai
succ :: Int -> Int succ x = x + 1
No side-effect.
Real World is full of side-effects.
getLine
putStr
rand
getLine :: RealWorld -> (RealWorld, String) putStr :: (RealWorld, String) -> RealWorld
echo :: RealWorld -> RealWorld echo rw0 = let (rw1, str) = getLine rw0 rw2 = putStr (rw1, str) in rw2
getLine :: IO String putStr :: String -> IO ()
echo :: IO () echo = getLine >>= putStr
class Functor m where fmap :: (a -> b) -> m a -> m b class Functor m => Applicative m where pure :: m a <*> :: m (a -> b) -> m a -> m b class Applicative m => Monad m where >>= :: m a -> (a -> m b) -> m b
Monad
Negation, universals, existentials, ...
data ℕ : Set where zero : ℕ suc : ℕ → ℕ _+_ : ℕ → ℕ → ℕ zero + n = n (suc m) + n = suc (m + n)
+-assoc : ∀ (m n p : ℕ) → (m + n) + p ≡ m + (n + p) +-assoc zero n p = begin (zero + n) + p ≡⟨⟩ n + p ≡⟨⟩ zero + (n + p) ∎ +-assoc (suc m) n p = begin (suc m + n) + p ≡⟨⟩ suc (m + n) + p ≡⟨⟩ suc ((m + n) + p) ≡⟨ cong suc (+-assoc m n p) ⟩ suc (m + (n + p)) ≡⟨⟩ suc m + (n + p) ∎