add dup
authorJim <jim.pryor@nyu.edu>
Sun, 1 Feb 2015 19:12:39 +0000 (14:12 -0500)
committerJim <jim.pryor@nyu.edu>
Sun, 1 Feb 2015 19:12:39 +0000 (14:12 -0500)
topics/week1_advanced_notes.mdwn

index 2742a7f..9bac7eb 100644 (file)
@@ -165,12 +165,14 @@ Function composition, which mathematicians write as `f` &cir; `g`, is defined as
 
 We've already come across the `id` function, namely &lambda; `x. x`.
 
-Other common functions are `fst`, which takes two arguments and returns the first of them; `snd`, which takes two arguments and returns the second of them; and `swap`, which takes two arguments and returns them both but with their positions swapped. These functions can be defined like this:
+Other common functions are `fst`, which takes two arguments and returns the first of them; `snd`, which takes two arguments and returns the second of them; and `swap`, which takes two arguments and returns them both but with their positions swapped. A fourth function is `dup`, which takes one argument and returns it twice.
+These functions can be defined like this:
 
     let
       fst (x, y) = x;
       snd (x, y) = y;
-      swap (x, y) = (y, x)
-    in (fst, snd, swap)
+      swap (x, y) = (y, x);
+      dup x = (x, x)
+    in (fst, snd, swap, dup)