-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathski.carp
31 lines (30 loc) · 987 Bytes
/
ski.carp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
; the SKI combinator calculus in carp
;
; SKI is a calculus of three constructions:
; - `s`, which takes two functions and an argument,
; applying the second function to the argument and
; passing the result into the first function along
; with the original argument,
; - `k`, which takes two arguments and returns the
; first,
; - and `i`, which takes one argument and returns it
; as is—the identity function.
;
; while it might not be immediately obvious how this
; is useful at all, it’s actually quite powerful when
; combined with such things as church encodings.
;
; for a simple example, let’s consider doubling a
; number:
; (s + i 10)
; which will run the identity function on `10`, which
; will result in `10` being passed to `s` twice.
;
; the SKI module, containing the combinators.
; the combinators themselves should be relatively
; obvious from the description above.
(defmodule SKI
(defn s [f g x] (f x (g x)))
(defn k [x y] x)
(defn i [x] x)
)