Skip to content

Instantly share code, notes, and snippets.

@jasonzoladz
Created May 18, 2017 22:47
Show Gist options
  • Save jasonzoladz/7cb89b85c2778b95a24ea06417c5cb1a to your computer and use it in GitHub Desktop.
Save jasonzoladz/7cb89b85c2778b95a24ea06417c5cb1a to your computer and use it in GitHub Desktop.
Look Ma, no callbacks! (Using PureScript's Aff Monad with NodeJS.)
module Main where
import Prelude
import Control.Monad.Aff (attempt, forkAff, launchAff)
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Class (liftEff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Control.Monad.Eff.Exception (EXCEPTION)
import Data.Either (Either(..))
import Node.Encoding (Encoding(..))
import Node.FS (FS)
import Node.FS.Aff (readTextFile)
main :: forall e. Eff ( exception :: EXCEPTION
, fs :: FS
, console :: CONSOLE| e) Unit
main = void $ launchAff do
_ <- forkAff $ do
greet <- attempt $ readTextFile UTF8 "./greet.txt"
case greet of
Left err -> liftEff $ log "Error, yo!"
Right res -> liftEff $ log res
liftEff $ log "The last shall be first."
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment