On Thu, Dec 15, 2011 at 9:13 AM, Gregory Crosswhite
<[email protected]>wrote:

> To quote Ross Paterson's proposals:
>
> instance Alternative [] where
>    ...
>    some [] = []
>    some (x:xs) = repeat (repeat x)
>
>    many [] = [[]]
>    many (x:xs) = repeat (repeat x)
>

Isn't this instance conflating the ZipList notion and the nondeterministic
list notion?


> • some v = (:) <$> v <*> many v
> • many v = some v <|> pure []
>

Is there a motivation for writing the second law like this and not like

    many v = pure [] <|> some v

other than "parsers should try longest match first"? Because apart from
that, I find the version with flipped arguments to <|> more natural (base
case first). Incidentally, it would lead to terminating definitions of
'some' and 'many' for lists:

    ghci> take 5 . map (take 5) $ some [1,2]
    [[1],[1,1],[1,1,1],[1,1,1,1],[1,1,1,1,1]]
    ghci> take 5 . map (take 5) $ many [1,2]
    [[],[1],[1,1],[1,1,1],[1,1,1,1]]

Sebastian
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to