[Haskell-cafe] Data.Tree.Zipper in the standard libraries

Don Stewart dons at galois.com
Fri May 23 13:45:04 EDT 2008


Using 'monad' here makes it easier to make a mistake with the code, as
it permits new kinds of unexpected failure.

This is Haskell, we should use Maybe.

And users that want it can lift Maybe a -> m a

-- Don

(-1) for new uses of fail in place of Nothing.

kr.angelov:
> The monads design is used in Data.Map i.e.
> 
> lookup :: (Monad m, Ord k) => k -> Map k a -> m a
> 
> and I think that this will be more consistent.
> 
> 
> On 5/23/08, Ross Paterson <ross at soi.city.ac.uk> wrote:
> > On Fri, May 23, 2008 at 09:03:29AM +0200, Krasimir Angelov wrote:
> > > Alternatively I can use monad with failure. In other words, there are
> > > two possibilities:
> > >
> > > 1. Use error ".." and types like:   TreeLoc a -> TreeLoc a
> > > 2. Use monad and type like:       Monad m => TreeLoc a -> m (TreeLoc a)
> >
> > I'd suggest that TreeLoc a -> Maybe (TreeLoc a) is better than the
> > second version.  The problem with using Monad(fail) is that it hides
> > possible runtime errors among testable conditions.  With 1. you can
> > at least search the code for occurrences of the dangerous function.
> > With the Monad version you need to consider the type of each use to know
> > whether it is dangerous.
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-Cafe at haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
> >
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe


More information about the Haskell-Cafe mailing list