Use null for erased values to aid serialization

This commit is contained in:
2025-01-18 14:48:29 -08:00
parent cecb1d73c1
commit f9279bb255
6 changed files with 43 additions and 28 deletions

View File

@@ -5,11 +5,11 @@ import Prelude
-- We should test this at some point
ptype IORef : U U
pfunc primNewIORef uses (MkIORes MkUnit) : a. a IO (IORef a) := `(_, a) => (w) => MkIORes(undefined, [a], w)`
pfunc primReadIORef uses (MkIORes MkUnit) : a. IORef a IO a := `(_, ref) => (w) => MkIORes(undefined, ref[0], w)`
pfunc primNewIORef uses (MkIORes MkUnit) : a. a IO (IORef a) := `(_, a) => (w) => MkIORes(null, [a], w)`
pfunc primReadIORef uses (MkIORes MkUnit) : a. IORef a IO a := `(_, ref) => (w) => MkIORes(null, ref[0], w)`
pfunc primWriteIORef uses (MkIORes MkUnit) : a. IORef a a IO Unit := `(_, ref, a) => (w) => {
ref[0] = a
return MkIORes(undefined,MkUnit,w)
return MkIORes(null,MkUnit,w)
}`
newIORef : io a. {{HasIO io}} a io (IORef a)

View File

@@ -236,7 +236,7 @@ expToDoc (Apply x xs) = expToDoc x ++ text "(" ++ nest 2 (commaSep (map expToDoc
expToDoc (Var nm) = jsIdent nm
expToDoc (JLam nms (JReturn exp)) = text "(" <+> commaSep (map jsIdent nms) <+> text ") =>" <+> text "(" ++ expToDoc exp ++ text ")"
expToDoc (JLam nms body) = text "(" <+> commaSep (map jsIdent nms) <+> text ") =>" <+> bracket "{" (stmtToDoc body) "}"
expToDoc JUndefined = text "undefined"
expToDoc JUndefined = text "null"
expToDoc (Index obj ix) = expToDoc obj ++ text "(" ++ expToDoc ix ++ text " :: Nil)"
expToDoc (Dot obj nm) = expToDoc obj ++ text "." ++ jsIdent nm

View File

@@ -8,12 +8,12 @@ pfunc readFile uses (fs MkIORes Left Right) : (fn : String) -> IO (Either String
let result
try {
let content = fs.readFileSync(fn, 'utf8')
result = Right(undefined, undefined, content)
result = Right(null, null, content)
} catch (e) {
let err = ""+e
result = Left(undefined, undefined, e)
result = Left(null, null, e)
}
return MkIORes(undefined, result, w)
return MkIORes(null, result, w)
}`
-- I wonder if I should automatically `uses` the constructors in the types
@@ -21,12 +21,12 @@ pfunc writeFile uses (fs MkIORes MkUnit) : String → String → IO (Either Stri
let result
try {
fs.writeFileSync(fn, content, 'utf8')
result = Right(undefined, undefined, MkUnit)
result = Right(null, null, MkUnit)
} catch (e) {
let err = ""+e
result = Left(undefined, undefined, e)
result = Left(null, null, e)
}
return MkIORes(undefined, result, w)
return MkIORes(null, result, w)
}`
-- maybe System.exit or something, like the original putStrLn msg >> exitFailure