Created
February 29, 2020 00:39
-
-
Save belisarius222/d67c265cd946a5f8ad9eb6d86e3b9ae4 to your computer and use it in GitHub Desktop.
monads.hoon
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
|% | |
++ mebe | |
|* a=mold | |
|% | |
+$ form (unit a) | |
++ pure | |
|= arg=a | |
^- form | |
`u=arg | |
++ bind | |
|* b=mold | |
|= [m-b=(unit b) fun=$-(b form)] | |
^- form | |
?~ m-b | |
~ | |
(fun u.m-b) | |
-- | |
++ cheq | |
|* e=mold | |
|* a=mold | |
|% | |
+$ form (each a e) | |
++ pure | |
|= ok=a | |
^- form | |
&+ok | |
++ bind | |
|* b=mold | |
|= [m-b=(each b e) fun=$-(b form)] | |
^- form | |
?- -.m-b | |
%& (fun p.m-b) | |
%| m-b | |
== | |
-- | |
++ tests | |
|% | |
++ test-mebe-bind-null ^- tang | |
=/ m (mebe ,@) | |
=/ a=form:m ~ | |
%+ expect-eq | |
!> ((bind:m ,@) a |=(@ `u=(add 17 +<))) | |
!> `form:m`~ | |
:: | |
++ test-mebe-bind-pure ^- tang | |
=/ m (mebe ,@) | |
=/ a=form:m (pure:m 12) | |
%+ expect-eq | |
!> ((bind:m ,@) a |=(@ `u=(add 17 +<))) | |
!> (pure:m 29) | |
:: | |
++ test-mebe-mcgl ^- tang | |
=/ m (mebe ,@) | |
=/ twelve | |
;< x=@ bind:m (pure:m 12) | |
;< y=@ bind:m `(add 17 x) | |
(pure:m (sub y 17)) | |
%+ expect-eq | |
!> twelve | |
!> (pure:m 12) | |
:: | |
++ test-cheq-bind-null ^- tang | |
=/ m ((cheq ,tang) ,@) | |
=/ a=form:m |+~ | |
%+ expect-eq | |
!> ((bind:m ,@) a |=(@ &+(add 17 +<))) | |
!> `form:m`|+~ | |
:: | |
++ test-cheq-bind-pure ^- tang | |
=/ m ((cheq ,tang) ,@) | |
=/ a=form:m (pure:m 12) | |
%+ expect-eq | |
!> ((bind:m ,@) a |=(@ &+(add 17 +<))) | |
!> (pure:m 29) | |
:: | |
++ test-cheq-mcgl ^- tang | |
=/ m ((cheq ,tang) ,@) | |
=/ twelve | |
;< x=@ bind:m (pure:m 12) | |
;< y=@ bind:m &+(add 17 x) | |
(pure:m (sub y 17)) | |
%+ expect-eq | |
!> twelve | |
!> (pure:m 12) | |
-- | |
-- |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment