X-Git-Url: http://lambda.jimpryor.net/git/gitweb.cgi?p=lambda.git;a=blobdiff_plain;f=topics%2Fweek1_advanced_notes.mdwn;h=9bac7eb64fbec8625f85a055d59b1bac6d52067a;hp=2742a7fc330cbda2e135bd2f6b91c934a9aecadc;hb=222fceeec976f4e512b5d24969b54ae71ff473a3;hpb=536b3ca117f2fbd3fecc229e62a63a41294428d3 diff --git a/topics/week1_advanced_notes.mdwn b/topics/week1_advanced_notes.mdwn index 2742a7fc..9bac7eb6 100644 --- a/topics/week1_advanced_notes.mdwn +++ b/topics/week1_advanced_notes.mdwn @@ -165,12 +165,14 @@ Function composition, which mathematicians write as `f` ○ `g`, is defined as We've already come across the `id` function, namely λ `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)