Skip to content

Instantly share code, notes, and snippets.

fromResult :: Result a -> Maybe a
fromResult (Ok k) = Just k
fromResult (Error e) = Nothing
maybeFromObj :: JSON a => String -> JSObject JSValue -> Maybe a
maybeFromObj k o = maybe (Nothing) (fromResult . readJSON) (lookup k (fromJSObject o))
@tsurushuu
tsurushuu / gist:1240214
Created September 25, 2011 04:05
readFile catch test.
import System.IO (hPutStrLn, stderr)
import Control.Exception (catch, IOException, SomeException)
import Prelude hiding (catch)
readFileWithDefault :: FilePath -> String -> IO String
readFileWithDefault filepath defaultString =
catch
(readFile filepath)
(\e -> do
return (e::SomeException)