stew / codebase

0 stars 2 forks source link

`some` and `many` are named the opposite than the Haskell Alternative functions #7

Closed hagl closed 2 years ago

hagl commented 2 years ago

The parsers have following semantic: some : Parser e t a -> Parser e t [a] : matches zero or more many : Parser e t a -> Parser e t [a] : matches one or more

while in Haskell the functions of Alternative from Control.Applicative have

some :: 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 of List for the one that must match at lease onces, e.g. have

many : Parser e t a -> Parser e t [a] some : Parser e t a -> Parser e t (Nonempty a)

What do you think?

hagl commented 2 years ago

image

ceedubs commented 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:

stew commented 2 years ago

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 :)