Skip to content

Instantly share code, notes, and snippets.

@denisshevchenko
Created February 23, 2018 15:43
Show Gist options
  • Save denisshevchenko/c089b4de7a7f6b22492f693f9c7ea67b to your computer and use it in GitHub Desktop.
Save denisshevchenko/c089b4de7a7f6b22492f693f9c7ea67b to your computer and use it in GitHub Desktop.
import System.Directory
data FileError = NoSuchFile deriving (Show)
readMyFile :: FilePath -> IO (Either FileError String)
readMyFile pathToFile = do
fileIsHere <- doesFileExist pathToFile
if fileIsHere then do
content <- readFile pathToFile
return $ Right content
else
return $ Left NoSuchFile
main :: IO ()
main = do
result <- readMyFile $ "/home/denis/Code/cardano-sl/nixpkgs-src.json"
case result of
Left problem -> print problem
Right content -> print content
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment