shajra / haskell-exceptions-checked Goto Github PK
View Code? Open in Web Editor NEWStatically Checked Exceptions for Haskell
License: BSD 3-Clause "New" or "Revised" License
Statically Checked Exceptions for Haskell
License: BSD 3-Clause "New" or "Revised" License
I could remove the MonadFail
instance from Checked
, but MonadPlus
and Alternative
are unfortunate to remove. Really, the problem isn't these type classes. The problem is that IO
throws exceptions in the instances for these type classes.
So maybe for IO
, I should make a newtype. If you use IO
directly, then the warning is merely not to call mzero
or fail
. But if you use the newtype I provide for IO
, then you're safer, because I won't expose exception-throwing instances for any type classes.
This example shows how we can use Caught
directly to bypass safety:
{-# LANGUAGE FlexibleContexts #-}
module Main where
import Control.Exception.Checked
import Control.Monad
import Data.Proxy
falseSecurity :: Throws IOException e => CheckedIO e String
falseSecurity =
throws' (Proxy :: Proxy IOException) $ readFile "no file here"
harshReality :: CheckedIO (Caught IOException e) String
harshReality = falseSecurity
-- explodes
main :: IO ()
main = void $ runChecked harshReality
This doesn't use fancy extensions that have come out since the 2009 paper Explicitly Typed Exceptions for Haskell, so the problem was there even in the original work. And this paper suggests exposing Caught
to support explicitly typed user-created exception hierarchies. So in a way, we want to expose Caught
as an implementation detail that can be extended. But we also want to discourage users from trying to use it directly.
So I'm thinking I'll create an “Internal” module with everything, and then re-export what's safe out in the normal module.
I'm kind of eager to use Checked
with monad transformers, and not just a raw IO
.
monad-control
doesn't have a great user experience (the boilerplate to create MonadBaseControl
and MonadTransControl
instances, for example), but it does solve a problem with monad transformers; we want to be able to unstack the transformer stack to get to the base, run a function, and then stack everything back again.
And as a second step, maybe make another module for unliftio
. That way I'm not forcing people to chose between MonadBase
and MonadIO
.
But maybe this is all a low priority because the exceptions
approach of Monad{Catch,Throw,Mask}
can go far enough.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.