Last active
November 2, 2018 16:55
-
-
Save zindel/067c9010c24c355216b08aedb2a9c540 to your computer and use it in GitHub Desktop.
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
| module Action = { | |
| type t('i, 'o) = 'i => 'o; | |
| let chain = (action1, action2, arg) => arg |> action1 |> action2; | |
| }; | |
| module Rule = { | |
| type t('i, 'o) = { | |
| action: Action.t('i, 'o), | |
| f: option(unit), | |
| }; | |
| let make = action => {action, f: None}; | |
| let chain = ({action: a1, _}, {action: a2, _}) => { | |
| action: Action.chain(a1, a2), | |
| f: None, | |
| }; | |
| let execute = (input, {action, _}) => action(input); | |
| }; | |
| let test = () => { | |
| let hello = Rule.make(() => "Hello"); | |
| let plusWorld = Rule.make(s => s ++ ", world"); | |
| let print = Rule.make(print_endline); | |
| let all = Rule.(chain(chain(hello, plusWorld), print)); | |
| Rule.execute((), all); | |
| }; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment