[Haskell-cafe] A very nontrivial parser

Andrew Coppin andrewcoppin at btinternet.com
Thu Jul 5 15:45:14 EDT 2007

Jonathan Cast wrote:
> On Thursday 05 July 2007, Andrew Coppin wrote:
>> ...OK, anybody have a solution that works in Haskell 98?
> Rank-2 types are perhaps /the/ most common, widely accepted extension to 
> Haskell 98, after the approved addendum for FFI and the draft addendum for 
> hierarchical modules.  I would really be concerned about using them (it's 
> certainly not like they're going to just disappear on you one day, like say 
> functional dependencies almost certainly will).  But that's just me.

Personally, I just try to avoid *all* language extensions - mainly 
because most of them are utterly incomprehensible. (But then, perhaps 
that's just because they all cover extremely rare edge cases?)

MPTCs and ATs look useful. The rest... hmm. If I ever figure out what 
they do, maybe I can comment.

>> 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...?)
> Just a side point but: how would it know?  Leaving aside the 
> dictionary-passing used for type classes, Haskell has (and has always had) a 
> type-erasure semantics, which rules out runtime type errors.

Usually if you have something like

  let (Foo x) = process x y z

and it turns out that the 'process' function returns another 
constructor, you get an error. Well you'd expect the same thing to 
happen if the result type happens to be a 'hidden' type. But apparently 

>> So *neeer* :-P
> My first thought is that surely you must have said
> newtype Parser state x y
>   = forall src. Source src => Parser ((state, src x) -> (state, src x, y))
> when you meant
> newtype Parser state x y
>   = Parser (forall src. Source src => (state, src x) -> (state, src x, y))
> The relative order of the constructor name and the forall is very important!  

Care to explain what's different about these apparently identical 

More information about the Haskell-Cafe mailing list