Created
May 31, 2019 15:06
-
-
Save hsk/f4759fccd576c2f04d4eddf51fd74aea to your computer and use it in GitHub Desktop.
This file contains 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
function or(...ps) { | |
return (x) => { | |
for(var i = 0; i< ps.length;i++) | |
if (ps[i](x)) return true | |
return false | |
} | |
} | |
function i(x) { | |
return Number.isInteger(x) | |
} | |
function s(x) { | |
return (i) => i == x | |
} | |
function a(...ps) { | |
return (is) => { | |
if (is.length != ps.length) return false; | |
for(var i=0; i< is.length; i++) | |
if(!ps[i](is[i])) return false; | |
return true; | |
} | |
} | |
function o(os) { | |
return (is) => { | |
for(var i in os) { | |
if(!os[i](is[i])) return false | |
} | |
return true | |
} | |
} | |
function delay(f) { | |
return (i) => f()(i) | |
} | |
function assert(a) { | |
if(!a) throw a; | |
} | |
var e = delay(()=>or(i,a(s("add"),e,e),a(s("mul"),e,e))) | |
assert(e(1)); | |
assert(e(["add",1,["mul",2,3]])); | |
var t = delay(()=>or(i,o({tag:s("add"),l:t,r:t}),o({tag:s("mul"),l:t,r:t}))) | |
assert(t(1)); | |
assert(t({tag:"add",l:1,r:{tag:"mul",l:2,r:3}})) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment