Skip to content

Instantly share code, notes, and snippets.

@dredozubov
Last active August 29, 2015 14:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dredozubov/d03686f58ff9a24f23bb to your computer and use it in GitHub Desktop.
Save dredozubov/d03686f58ff9a24f23bb to your computer and use it in GitHub Desktop.
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