Skip to content

Instantly share code, notes, and snippets.

@Thimoteus
Created March 3, 2016 21:25
Show Gist options
  • Save Thimoteus/af1b459568100a0f3f33 to your computer and use it in GitHub Desktop.
Save Thimoteus/af1b459568100a0f3f33 to your computer and use it in GitHub Desktop.
When the typesystem fails
module Main where
import Prelude
import Control.Monad.Eff (Eff)
import Control.Monad.Eff.Console (CONSOLE, log)
import Control.Monad.Eff.Exception (EXCEPTION, Error, catchException, message)
import Node.FS (FS)
import Node.FS.Sync (stat)
import Data.Traversable (traverse)
import Data.Either (Either(..))
catch :: forall a eff. Eff ( err :: EXCEPTION | eff ) a -> Eff eff (Either Error a)
catch e = catchException (pure <<< Left) (e >>= pure <<< Right)
arr :: Array String
arr = ["these", "do", "not", "exist"]
main :: forall e. Eff (console :: CONSOLE, fs :: FS | e) Unit
main = do
xs <- catch $ traverse stat arr
case xs of
Left err -> log $ message err
_ -> log "success!"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment