[Haskell-cafe] Splitting off many/some from Alternative

Felipe Almeida Lessa felipe.lessa at gmail.com
Thu Dec 15 02:06:06 CET 2011


Ok, sorry for the spam, accidentaly hit the send button =/.

On Wed, Dec 14, 2011 at 11:03 PM, Felipe Almeida Lessa
<felipe.lessa at gmail.com> wrote:
> On Wed, Dec 14, 2011 at 4:09 PM, James Cook <mokus at deepbondi.net> wrote:
>> So a case could be made that, just as "forever (Just 1)" being nonsensical
>> doesn't invalidate "instance Monad Maybe", "some (Just 1)" being nonsensical
>> doesn't invalidate "instance Alternative Maybe".  And on the other hand, a
>> case could be made that the importance of "some" and "many" justifies the
>> creation of a subclass of Alternative where they actually are mandated to be
>> meaningful rather than just definable.

Being in the same typeclass means that you can define

  instance Alternative Maybe where
    ...
    some Nothing = Nothing
    some (Just _) = error "Alternative.some: used with Just (loops forever)"
    many Nothing = Nothing
    many (Just _) = error "Alternative.many: used with Just (loops forever)"

Cheers,

-- 
Felipe.



More information about the Haskell-Cafe mailing list