Code Monkey home page Code Monkey logo

haskell-exceptions-checked's People

Contributors

shajra avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

haskell-exceptions-checked's Issues

IO's Alternative, MonadPlus, and MonadFail instances leak exceptions

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.

Caught should be internal

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.

Implement a Control.Exception.Checked.{Lifted,Unlift} 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.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.