[Haskell-beginners] combining a trifecta parser with FreshMT from unbound

Andreas Reuleaux reuleaux at web.de
Wed Jul 30 23:42:49 UTC 2014


OK, I have made some progress, and have uploaded two programs to
lpaste.net

* one that works:
  trifecta + unbound, works:
  http://lpaste.net/108457

* and one that doesn't
  trifecta + unbound, fails
  http://lpaste.net/108458

the working version is simpler, in that it defines PiParser just as a
type synonym

  type PiParser = FreshMT InnerParser

maybe I should be happy already that I got that working, e.g.

> parseTest (runInnerParser $ runFreshMT $ whiteSpace *> many identifier) " wow {- bla -} this rocks"
> ["wow","this","rocks"]

to install: cabal install trifecta + unbound in a sandbox e.g.


Now in the second version, I have in addition wrapped the FreshMT in a newtype

  newtype FreshT m a = F {
    runF :: FreshMT m a
     } deriving (Monad, Functor, Applicative, MonadPlus, MonadTrans)

  type PiParser = FreshT InnerParser

While this might not be necessary in this simple case here,
I can imagine situations, where doing so might come in handy.

Consequently have to add a few more instances for the parser:

  instance CharParsing PiParser where
  etc.
  

and of course I need an additional step of unwrapping with runF

  runInnerParser $ runFreshMT $ runF someparser

(In both versions TokenParser is defined on the PiParser)


I would expect that I can parse something like the above test string
similarily, but unfortunately this is not the case:


> parseTest (runInnerParser $ runFreshMT $ runF (whiteSpace *> many identifier)) "  oh too {- bla -} bad"
[]

I can at most parse one letter:

> parseTest (runInnerParser $ runFreshMT $ runF (whiteSpace *> identifier)) "oh too {- bla -} bad"
"o"

I don't really see, how wrapping the FreshMT in a newtype harms the parser?

Thanks in advance

-Andreas


More information about the Beginners mailing list