Async, HasIO, and get aoc examples working in web

This commit is contained in:
2024-11-26 20:05:25 -08:00
parent e2db5a77df
commit a8363c7a45
8 changed files with 103 additions and 43 deletions

View File

@@ -266,11 +266,20 @@ instance Monad IO where
MkIORes a w => mab a w
pure a = \ w => MkIORes a w
pfunc putStrLn uses (MkIORes MkUnit) : String -> IO Unit := `(s) => (w) => {
class HasIO (m : U -> U) where
liftIO : a. IO a m a
instance HasIO IO where
liftIO a = a
pfunc primPutStrLn uses (MkIORes MkUnit) : String -> IO Unit := `(s) => (w) => {
console.log(s)
return MkIORes(undefined,MkUnit,w)
}`
putStrLn : io. {{HasIO io}} -> String -> io Unit
putStrLn s = liftIO (primPutStrLn s)
pfunc showInt : Int -> String := `(i) => String(i)`
class Show a where
@@ -322,8 +331,8 @@ instance Sub Int where
instance Ord Int where
x < y = ltInt x y
printLn : {a} {{Show a}} a IO Unit
printLn a = putStrLn $ show a
printLn : {m} {{HasIO m}} {a} {{Show a}} a m Unit
printLn a = putStrLn (show a)
-- opaque JSObject
ptype JSObject