-
Notifications
You must be signed in to change notification settings - Fork 1
/
6.js
47 lines (37 loc) · 976 Bytes
/
6.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
/*
* Simple haskell do-notation in javascript
* With blackgens and yieldches
*
*/
let { Nothing, Just, doM } = require('./optional');
let result = new Just(5).bindM(value =>
new Just(6).bindM(value2 =>
new Just(value + value2)));
console.log('Result:');
console.log(result);
//-----------------------------------------
let result2 = new Just(5).bindM(addSixM);
console.log('Result2:');
console.log(result2);
function addSixM(val) {
return new Just(6).bindM(addM.bind(null, val));
}
function addM(val1, val2) {
return new Just(val1 + val2);
}
//-----------------------------------------
let result3 = doM(function*() {
var value = yield new Just(5);
var value2 = yield new Just(6);
return new Just(value + value2);
}());
console.log('Result3:');
console.log(result3);
//------------------------------------------------
/*
* Exercise
*
* If you are god then
* Learn you a Haskell for Greater Good!
*
*/