Created
December 4, 2015 16:23
-
-
Save gallais/47d628be691e0e0f06c1 to your computer and use it in GitHub Desktop.
"Difference Nats" and addition by recursion on the first / second argument
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
type z = Z | |
type +'a s = S | |
type _ nat = | |
| Z : ('l * 'l) nat | |
| S : ('l * 'm) nat -> ('l * 'm s) nat | |
let rec add : type l m n . (l*m) nat -> (m*n) nat -> (l*n) nat = | |
fun i1 i2 -> match i2 with | |
| Z -> i1 | |
| S i -> S (add i1 i) (* OK *) | |
let rec shift : type l m. (l*m) nat -> (l s * m s) nat = function | |
| Z -> Z | |
| S i -> S (shift i) | |
let rec add2 : type l m n . (l*m) nat -> (m*n) nat -> (l*n) nat = | |
fun i1 i2 -> match i2 with | |
| Z -> i1 | |
| S i -> add2 (S i1) (shift i) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment