-
-
Save dredozubov/d03686f58ff9a24f23bb to your computer and use it in GitHub Desktop.
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
import qualified Data.ByteString as BS | |
instance FromJSON Config where | |
parseJSON (Object o) = ... | |
parseConfig :: FilePath -> IO (Either String Config) | |
parseConfig fp = BS.readFile fp >>= return . eitherDecode | |
main :: IO () | |
main = do | |
optionalDecoded <- parseConfig "optional.json" | |
config <- case optionalDecoded of | |
(Left err) -> parseConfig "default.json" | |
(Right v) -> return optionalDecoded | |
either handleError doWhatYouGonnaDo |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment