[Haskell-cafe] A very nontrivial parser

Andrew Coppin andrewcoppin at btinternet.com
Thu Jul 5 13:45:28 EDT 2007


Jonathan Cast wrote:
> On Wednesday 04 July 2007, Andrew Coppin wrote:
>   
>> Anybody have a solution to this?
>>     
>
> newtype Parser state x y
>   = Parser (forall src. Source src => (state, src x) -> (state, src x, y))
>   

...OK, anybody have a solution that works in Haskell 98?

> Definition of monad functions, etc, works exactly as for your version.

Not so.

In fact, doing this causes all mannar of malfunctions. First I get lots 
of messages of the form

"Cannot (yet) use update syntax on non-Haskell98 types."

Then I get lots of

"Cannot use function 'foo' as a selector."

And then I get

"My brain has exploded. I can't handle pattern bindings in 
existentially-quantified type constructors."

(?!)

And after that I get

"Type variable 'bar' escapes pattern binding."

And finally, after I correct all of those, I get an error saying that 
the compiler can't match [the hidden type variable] against [some 
suitable type for that variable]. And in a pattern of all things! 
(Surely if it's not the right type at runtime, it should generate an 
exception, just like if you use the wrong constructor...?)

In all, the whole thing just malfunctions horribly and I can get no 
useful work done! >_<

So my next plan was to write the code as normal, and then create a 
front-end module which "hides" all the messy types. But then I just get 
a whole bunch of "escaping type variable" errors again.

Basically everything I tried make the code drastically more complicated, 
and even *then* certain parts of it (most especially the stack function) 
wouldn't compile.

So *neeer* :-P



More information about the Haskell-Cafe mailing list