Closed hagl closed 2 years ago
Thanks for pointing this out @hagl !
I really like your idea of using Nonempty
to express this in the types.
I also don't think that some
and many
are very intuitive names. Throwing some options out there:
zeroOrMore
/ oneOrMore
listOf
/ 'nonemptyListOf`This really blew my mind, as I learned these from scalaz where they were the opposite way. They've since been removed completely but I had to go dig back in the history to ensure I wasn't crazy :)
I decided for now to rename them to many0
and many1
after surveying a dozen other parser generators :)
The parsers have following semantic:
some : Parser e t a -> Parser e t [a]
: matches zero or moremany : Parser e t a -> Parser e t [a]
: matches one or morewhile in Haskell the functions of
Alternative
fromControl.Applicative
havesome :: f a -> f [a]
: One or more.many :: f a -> f [a]
: Zero or more.I'm trying to port a Megaparsec parser and got confused by this names more than once.
I was also wondering if it makes sense to express the difference in the types by using
Nonempty
instead ofList
for the one that must match at lease onces, e.g. havemany : Parser e t a -> Parser e t [a]
some : Parser e t a -> Parser e t (Nonempty a)
What do you think?