refactoring in playground, use zip file for web
This commit is contained in:
26
playground/samples/aoc2023/Web.newt
Normal file
26
playground/samples/aoc2023/Web.newt
Normal file
@@ -0,0 +1,26 @@
|
||||
module Web
|
||||
|
||||
import Prelude
|
||||
|
||||
ptype Async : U -> U
|
||||
pfunc resolve : ∀ a. a -> Async a := `(_, a) => Promise.resolve(a)`
|
||||
pfunc andThen : ∀ a b. Async a -> (a -> Async b) -> Async b := `(A,B,a,ab) => a.then(ab)`
|
||||
pfunc reject : ∀ a. String -> Async a := `(_, msg) => Promise.reject(msg)`
|
||||
|
||||
instance Monad Async where
|
||||
bind = andThen
|
||||
pure = resolve
|
||||
|
||||
-- It'd be nice to be able to declare operators and JS "projections"
|
||||
pfunc fetchText : String -> Async String := `async (url) => {
|
||||
let response = await fetch(url)
|
||||
return response.text()
|
||||
}`
|
||||
|
||||
pfunc liftAsync : ∀ a. IO a -> Async a := `(_, a) => Promise.resolve(a(undefined).h0)`
|
||||
|
||||
instance HasIO Async where
|
||||
liftIO = liftAsync
|
||||
|
||||
runAsync : ∀ a. Async a -> IO Unit
|
||||
runAsync foo = pure MkUnit
|
||||
Reference in New Issue
Block a user