Last active
August 23, 2017 11:25
-
-
Save ehamberg/1bcee0949c5cddd02cfe3425c0f5485b to your computer and use it in GitHub Desktop.
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
-- code based on https://www.youtube.com/watch?v=umiUJNcvPl0 | |
data Command : Type -> Type where | |
PutStr : String -> Command () | |
GetStr : Command String | |
data InfIO : Type where | |
Do : Command a -> (a -> Inf InfIO) -> InfIO | |
(>>=) : Command a -> (a -> Inf InfIO) -> InfIO | |
(>>=) = Do | |
runCommand : Command a -> IO a | |
runCommand (PutStr x) = putStr x | |
runCommand GetStr = getLine | |
-- a run function: | |
run : InfIO -> IO () | |
run (Do command rest) = do res <- runCommand command | |
run (rest res) | |
-- expanding `do` notation and doing eta reduction fails: | |
run (Do command rest) = runCommand command >>= run . rest | |
-- `-- test.idr line 17 col 51: | |
-- When checking right hand side of run with expected type | |
-- IO () | |
-- | |
-- When checking an application of function Prelude.Basics..: | |
-- Type mismatch between | |
-- a -> Inf InfIO (Type of rest) | |
-- and | |
-- a -> InfIO (Expected type) | |
-- | |
-- Specifically: | |
-- Type mismatch between | |
-- Inf InfIO | |
-- and | |
-- InfIO | |
-- inserting a `Force` fixes it: | |
run (Do command rest) = runCommand command >>= run . Force . rest |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment