with-variables: Monads has its own bind word. missed one bind in koszul.
parent
1da8666a70
commit
6f2968b404
|
@ -55,7 +55,7 @@ SYMBOL: terms
|
||||||
|
|
||||||
! Addition
|
! Addition
|
||||||
: (alt+) ( x -- )
|
: (alt+) ( x -- )
|
||||||
terms get [ [ swap +@ ] assoc-each ] bind ;
|
terms get [ [ swap +@ ] assoc-each ] with-variables ;
|
||||||
|
|
||||||
: alt+ ( x y -- x+y )
|
: alt+ ( x y -- x+y )
|
||||||
[ >alt ] bi@ [ (alt+) (alt+) ] with-terms ;
|
[ >alt ] bi@ [ (alt+) (alt+) ] with-terms ;
|
||||||
|
|
|
@ -10,7 +10,7 @@ IN: monads.tests
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ nothing ] [
|
[ nothing ] [
|
||||||
111 just [ maybe-monad fail ] with-variables
|
111 just [ maybe-monad fail ] bind
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ 100 ] [
|
[ 100 ] [
|
||||||
|
@ -26,7 +26,7 @@ IN: monads.tests
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ { } ] [
|
[ { } ] [
|
||||||
{ 1 2 3 } [ drop "OOPS" array-monad fail ] with-variables
|
{ 1 2 3 } [ drop "OOPS" array-monad fail ] bind
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ 5 ] [
|
[ 5 ] [
|
||||||
|
@ -34,7 +34,7 @@ IN: monads.tests
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ 8 ] [
|
[ 8 ] [
|
||||||
5 state-monad return [ 3 + state-monad return ] with-variables
|
5 state-monad return [ 3 + state-monad return ] bind
|
||||||
"initial state" run-st
|
"initial state" run-st
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
@ -52,9 +52,9 @@ IN: monads.tests
|
||||||
|
|
||||||
[ 15 ] [
|
[ 15 ] [
|
||||||
f state-monad return
|
f state-monad return
|
||||||
[ drop get-st ] with-variables
|
[ drop get-st ] bind
|
||||||
[ 4 + put-st ] with-variables
|
[ 4 + put-st ] bind
|
||||||
[ drop get-st ] with-variables
|
[ drop get-st ] bind
|
||||||
11 run-st
|
11 run-st
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
@ -104,12 +104,12 @@ LAZY: nats-from ( n -- list )
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ 6 ] [
|
[ 6 ] [
|
||||||
f reader-monad return [ drop ask ] with-variables [ 1 + ] local 5 run-reader
|
f reader-monad return [ drop ask ] bind [ 1 + ] local 5 run-reader
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
[ f { 1 2 3 } ] [
|
[ f { 1 2 3 } ] [
|
||||||
5 writer-monad return
|
5 writer-monad return
|
||||||
[ drop { 1 2 3 } tell ] with-variables
|
[ drop { 1 2 3 } tell ] bind
|
||||||
run-writer
|
run-writer
|
||||||
] unit-test
|
] unit-test
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue