mrkkrp / parser-combinators

Lightweight package providing commonly useful parser combinators
Other
52 stars 15 forks source link

Provide Control.Applicative.Combinators.Expr #35

Closed turion closed 3 years ago

turion commented 3 years ago

The definitions in Control.Monad.Combinators.Expr are the only ones that don't exist as an Alternative version. Is it possible to create those as well?

mrkkrp commented 3 years ago

I would merge a PR adding that.

turion commented 3 years ago

I read the source a bit closer:

addPrecLevel :: MonadPlus m => m a -> [Operator m a] -> m a
addPrecLevel term ops =
  term' >>= \x -> choice [ras' x, las' x, nas' x, tern' x, return x]
  where
    ...

It seems to me that this is a usage of >>= that can't be replicated only with Applicative, right? But requiring a constraint (Monad m, Alternative m) without MonadPlus m seems silly. So I guess it actually can't be done?

We could still try and reduce MonadPlus m usage here and there (e.g. pTerm only needs Alternative I believe), but I guess we can't get rid of it completely?

mrkkrp commented 3 years ago

Indeed, perhaps that's the reason there is no applicative version.

turion commented 3 years ago

Ok I guess I'll close then until I have a better idea on what we could do.