[Haskell-beginners] Fwd: Factor out parsec types

Francesco Ariis fa-ml at ariis.it
Tue Mar 24 18:52:07 UTC 2020


Before replying, my example should have of course been:

    type MyPar a = ParsecT String () Identity a

On Tue, Mar 24, 2020 at 06:08:42PM +0100, Max Gautier wrote:
> If I understand correctly the parsec interface, leaving the stream
> type s as a type variable
> allows me to specify the concrete stream type at the time of use
> without changing the parser,
> as long as that stream gives Char tokens, is that correct ?
> And using a concrete stream type forfeit that, does'nt it ?

Yes you do forfeit polymorphism using a concrete type.
With your current synonym:

    type Parser s = ParsecT s () Identity

you already missing polymorphism on state (`()`) and a monadic
transformers (`Identity`).

Parsec itself [1] uses a very similar shorthand

    type Parser = Parsec String ()

[1] https://hackage.haskell.org/package/parsec-3.1.14.0/docs/Text-Parsec-String.html


I do not think there is a sensible way not to have the constraint
part (`... =>`) written out in full.


More information about the Beginners mailing list