mrkkrp / megaparsec

Industrial-strength monadic parser combinator library
Other
920 stars 87 forks source link

IndentOpt Existential Type #565

Open eayus opened 4 months ago

eayus commented 4 months ago

The current definition of IndentOpt exposes the type variable b representing the type of block elements to be parsed. In my opinion it makes more sense to existentially quantify this variable in the constructors instead. This gives block parsers more flexibility on the type of items they are parsing.

The current definition is like this:

data IndentOpt m a b
  = IndentNone a
  | IndentMany (Maybe Pos) ([b] -> m a) (m b)
  | IndentSome (Maybe Pos) ([b] -> m a) (m b)

and I am suggesting changing it to:

data IndentOpt m a
  = IndentNone a
  | forall b. IndentMany (Maybe Pos) ([b] -> m a) (m b)
  | forall b. IndentSome (Maybe Pos) ([b] -> m a) (m b)

This also gives the type a straightforward Functor instance.

Is this a change you would consider accepting? It is not backwards compatible and would require the ExistentialQuantification extension. I'd be happy to make a PR.

mrkkrp commented 2 months ago

This is probably better typing in this case, yes. It would make sense to merge this if we ever decide to bump the major version, but I'm not sure when that will happen.