Created
February 23, 2018 15:43
-
-
Save denisshevchenko/c089b4de7a7f6b22492f693f9c7ea67b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
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