Skip to content

Instantly share code, notes, and snippets.

@ympbyc
Last active December 30, 2015 17:59
Show Gist options
  • Save ympbyc/7865034 to your computer and use it in GitHub Desktop.
Save ympbyc/7865034 to your computer and use it in GitHub Desktop.
Typing Lambda Calculus & Generic Function & MOP
;;; there is no need for type Bool
(= (true a a a)
x y x)
(= (false a a a)
x y y)
;;; Twisted algebraic datatype
(= (cons a (List a) (List a))
x xs f
(f x xs))
(= (nil a (List a))
t
'nil)
(= (car (List a) a)
xs
(xs true))
(= (cdr (List a) (List a))
xs
(xs false))
;;; An example of MOP.
;;; The expression `(a b)` gets applied to generic function `call`
;;; at compile time to modify the AST.
;;`(1 + 2 + 3)`
(= (call Int (Fn Int a) a)
i f
(f i))
;;`(xs take 5 fold + 0)`
(= (call (List a) (Fn (List a) b) b)
xs f
(f xs))
(= (call (Fn a b) a b)
f x
(f x))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment