-
-
Save Thimoteus/af1b459568100a0f3f33 to your computer and use it in GitHub Desktop.
When the typesystem fails
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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