[Haskell-cafe] Splitting off many/some from Alternative
Antoine Latter
aslatter at gmail.com
Thu Dec 15 03:36:52 CET 2011
On Wed, Dec 14, 2011 at 8:03 PM, Ross Paterson <ross at soi.city.ac.uk> wrote:
> The current definition says that some and many should be the least
> solutions of the equations
>
> some v = (:) <$> v <*> many v
> many v = some v <|> pure []
>
> We could relax that to just requiring that they satisfy these equations
> (which I think is what John wants). In that case there would be another
> possible definition for Maybe:
>
> some Nothing = Nothing
> some (Just x) = Just (repeat x)
>
> many Nothing = Just []
> many (Just x) = Just (repeat x)
>
This seems to generalize to list:
some [] = []
some xs = [cycle xs]
many [] = [[]]
many xs = [cycle xs]
Although I'm still not sure why I would be using these operations in
maybe or list.
Antoine
> _______________________________________________
> 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