Last active
December 31, 2015 18:39
-
-
Save alpha123/8028402 to your computer and use it in GitHub Desktop.
"Dependently-typed" JS thing
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
// Syntax note: optionally whitespace-sensitive, \ is an alias for function, | |
// and -> at the end of a function means return the last value. | |
// Haskell-style (operator), which is implicit if an operator is the only | |
// argument to a function. | |
// The return value of a type function is compared to the value put in, | |
// and if they are === it type checks. | |
function Int(n) -> Math.floor(n) | |
function add(a: Int, b: Int) -> a + b | |
function Addable(value) -> value + value.constructor() | |
function add(a: Addable, b: Addable) -> a + b | |
function TypedArray(type) -> | |
function (value) -> value.every(\e -> type(e) === e)) ? value : NaN | |
function sum(array: TypedArray(Addable)) -> array.reduce(+) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment