Re: [Haskell-cafe] Views

2008-09-14 Thread Iavor Diatchki
Hi, On Sun, Sep 14, 2008 at 7:01 AM, Stephan Friedrichs <[EMAIL PROTECTED]> wrote: > I agree that the MonadZero class with a useful 'zero' :: m a would be > the right abstraction for views. But MonadZero is not part of base, mtl > or any other common package, or am I missing something? Changing th

Re: [Haskell-cafe] Views

2008-09-14 Thread Brandon S. Allbery KF8NH
On 2008 Sep 14, at 10:01, Stephan Friedrichs wrote: Johannes Waldmann wrote: I think the crux of the matter was that a monad is too general. Either there is a result or there is not. That's precisely the intended use of a Maybe. Indeed "Monad m =>" is dangerous here because not every Monad

Re: [Haskell-cafe] Views

2008-09-14 Thread Stephan Friedrichs
Johannes Waldmann wrote: >> I think the crux of >> the matter was that a monad is too general. Either there is a result or >> there is not. That's precisely the intended use of a Maybe. > > Indeed "Monad m =>" is dangerous here > because not every Monad has a reasonable definition of "fail". > >

Re: [Haskell-cafe] Views

2008-09-14 Thread Johannes Waldmann
I think the crux of the matter was that a monad is too general. Either there is a result or there is not. That's precisely the intended use of a Maybe. Indeed "Monad m =>" is dangerous here because not every Monad has a reasonable definition of "fail". But that seems to be a problem in the (c

Re: [Haskell-cafe] Views

2008-09-14 Thread Stephan Friedrichs
Johannes Waldmann wrote: >> a) ... to use Maybe >> b) ... to provide my own Data.Heap.View type > > leave the choice up to the programmer, > and provide a generic interface, > accepting any MonadZero (*) instance. > > cf. Data.Set.maxView AFAIK there has been a vivid discussion about that. I thi

Re: [Haskell-cafe] Views

2008-09-13 Thread Ryan Ingram
On Sat, Sep 13, 2008 at 11:19 AM, Stephan Friedrichs <[EMAIL PROTECTED]> wrote: > data View > = Empty > | Cons a (SomeDataStructure a) > > A good example for this is Data.Sequence. My question is: Why is this > not expressed in terms of Maybe? > > view :: SomeDataStructure a -> Maybe (a, SomeData

Re: [Haskell-cafe] Views

2008-09-13 Thread Johannes Waldmann
> a) ... to use Maybe > b) ... to provide my own Data.Heap.View type leave the choice up to the programmer, and provide a generic interface, accepting any MonadZero (*) instance. cf. Data.Set.maxView http://www.haskell.org/hoogle/?hoogle=maxView (*) ah - I forgot, MonadZero didn't quite make i

[Haskell-cafe] Views

2008-09-13 Thread Stephan Friedrichs
Hello! List-like data structures should IMHO provide safe versions of 'head' and 'tail' (with safe I mean 'not partial', i. e. functions that don't provoke an 'error' when called with an empty collection). As far as I know, this is usually called 'view' and and has a type signature like view :: S