Created
June 14, 2018 00:30
-
-
Save jonathanlking/b8ebf39fe5d6faf6fc33ae64541633d2 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 Main where | |
import Prelude | |
import Data.List | |
import Data.Newtype | |
import Data.Monoid (mempty) | |
-- From purescript-indexed-monad | |
class IxMonad m where | |
ipure ∷ ∀ a x. a → m x x a | |
ibind ∷ ∀ a b x y z. m x y a → (a → m y z b) → m x z b | |
infixl 1 ibind as :>>= | |
data Stopped | |
data Running | |
newtype Machine i o a = Machine a | |
instance ixMonadMachine :: IxMonad Machine where | |
ipure = Machine | |
ibind (Machine x) f = Machine <<< runMachine $ f x | |
runMachine :: forall s t a. Machine s t a -> a | |
runMachine (Machine x) = x | |
start :: Machine Stopped Running Unit | |
start = Machine unit | |
stop :: Machine Running Stopped Unit | |
stop = Machine unit | |
example1 :: Machine Running Running Unit | |
example1 = ipure unit | |
:>>= \_ -> stop | |
:>>= \_ -> start | |
-- Uncomment for error! | |
-- example2 :: Machine Running Running Unit | |
-- example2 = do | |
-- pure unit | |
-- stop | |
-- start | |
-- where | |
-- bind = (:>>=) | |
-- pure = ipure |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment