Skip to content

Instantly share code, notes, and snippets.

@dredozubov
Last active Aug 29, 2015
Embed
What would you like to do?
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