#2309: containers: specialize functions that fail in a Monad to Maybe

Krasimir Angelov kr.angelov at gmail.com
Sun May 25 03:39:21 EDT 2008


(+1) for Maybe

I think the proposal to generalize to MonadPlus is even worse. In this
case the function can indicate failure with either fail or mzero which
makes things even worse.

Regards,
  Krasimir


On Sun, May 25, 2008 at 1:59 AM, Ross Paterson <ross at soi.city.ac.uk> wrote:
> Several functions on containers used to have types like
>
>        lookup :: (Ord k) => k -> Map k a -> Maybe a
>
> but these were generalized to
>
>        lookup :: (Monad m, Ord k) => k -> Map k a -> m a
>
> The only methods of Monad used are return and fail. The problem is that,
> depending on the monad, fail can be an ordinary value or a runtime error:
> this device makes it harder to check whether a program is safe, because
> it hides possible runtime errors among testable conditions.
>
> The proposal is to change these signatures back, specializing them
> to Maybe.
>
> The functions involved are:
>
>        lookup :: Ord k => k -> Map k a -> Maybe a
>        lookupIndex :: Ord k => k -> Map k a -> Maybe Int
>        minViewWithKey :: Map k a -> Maybe ((k,a), Map k a)
>        maxViewWithKey :: Map k a -> Maybe ((k,a), Map k a)
>        minView :: Map k a -> Maybe (a, Map k a)
>        maxView :: Map k a -> Maybe (a, Map k a)
>
>        lookup :: Key -> IntMap a -> Maybe a
>        maxViewWithKey :: IntMap a -> Maybe ((Key, a), IntMap a)
>        minViewWithKey :: IntMap a -> Maybe ((Key, a), IntMap a)
>        maxView :: IntMap a -> Maybe (a, IntMap a)
>        minView :: IntMap a -> Maybe (a, IntMap a)
>
>        minView :: Set a -> Maybe (a, Set a)
>        maxView :: Set a -> Maybe (a, Set a)
>
>        maxView :: IntSet -> Maybe (Int, IntSet)
>        minView :: IntSet -> Maybe (Int, IntSet)
>
> No information is lost, because in each case there is a single failure
> mode.
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://www.haskell.org/mailman/listinfo/libraries
>


More information about the Libraries mailing list