[Haskell-cafe] [Alternative] summary of my understanding so far

Sebastian Fischer fischer at nii.ac.jp
Mon Dec 19 00:51:44 CET 2011


On Thu, Dec 15, 2011 at 9:13 AM, Gregory Crosswhite
<gcrosswhite at gmail.com>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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20111219/67dcc389/attachment.htm>


More information about the Haskell-Cafe mailing list