Last active
August 29, 2015 14:02
-
-
Save remydagostino/10824b9656e08387127c to your computer and use it in GitHub Desktop.
Haskell JS ideas
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
var haskellFunction = hs.create( | |
hs.when('[]', function() { | |
}), | |
hs.when('(x:xs)', | |
// | |
hs.gaurd(hs.gte(5), function(self, a, x, xs, b) { | |
}), | |
hs.gaurd(hs.lte(2), function(self, a, x, xs, b) { | |
}), | |
function(self, a, x, xs, b) { | |
}, | |
).where(function(x, xs) { | |
var a = 20, | |
b = 100; | |
return [a, x, xs, b]; | |
}); | |
); | |
// Alternate idea with types | |
var Phone = Type({name: String, number: String}); | |
var Person = Type({first: String, last: String, phones: [Phone]}); | |
var myPerson = Person('Sally', 'Dengus', [Phone('Home', '4444'), Phone('Mobile', '1234')]); | |
var doSomething = Func.create( | |
Func.signature([Person], Number).returns(String), | |
Func.when('_ 0', function() { | |
return ''; | |
}), | |
Func.when('[] _', function(self) { | |
return self([], 0); | |
}), | |
Func.when('x:xs n', function(self, a, x, xs, n) { | |
return first(x.phones).number + self(xs, n - 1); | |
}) | |
.using(function(x, xs, n) { | |
var a = 20; | |
return [a, x, xs, n]; | |
}); | |
); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment