27 lines
748 B
Agda
27 lines
748 B
Agda
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
|