Things and limitations...

Pablo E. Martinez Lopez fidel@cs.chalmers.se
Thu, 17 May 2001 12:08:01 +0200


I have made something very similar, and it worked. 
That work is reported in the paper "Generic Parser Combinators"
published in the 2nd Latin-American Conference on Functional Programming
(CLaPF). You can download it from
ftp://sol.info.unlp.edu.ar/pub/papers/theory/fp/2ndCLaPF/Papers/mlopez2.ps.gz
There I have made Hutton's parsers, Fokker's parsers and Rojemo's
parsers instances of a class Parser that looks similar to what you have
attempted. But it uses multiparameter type clases.
Sadly, Swiestra's parsers cannot be made instances of this class,
because they are not monads. 
I hope this will help you.
FF

Juan Carlos Arevalo Baeza wrote:
>     First, about classes of heavily parametric types. Can't be done, I
> believe. At least, I haven't been able to. What I was trying to do (as an
> exercise to myself) was reconverting Graham Hutton and Erik Meijer's
> monadic parser library into a class. Basically, I was trying to convert the
> static:
> 
> ---
> newtype Parser a = P (String -> [(a,String)])
> item :: Parser Char
> force :: Parser a -> Parser a
> first :: Parser a -> Parser a
> papply :: Parser a -> String -> [(a,String)]
> ---
> 
> ---
> class (MonadPlus (p s v)) => Parser p where
>      item :: p s v v
>      force :: p s v a -> p s v a
>      first :: p s v a -> p s v a
>      papply :: p s v a -> s -> [(a,s)]
> ---
> 
>     I have at home the actual code I tried to make work, so I can't just
> copy/paste it, but it looked something like this. Anyway, this class would
> allow me to define parsers that parse any kind of thing ('s', which was
> 'String' in the original lib), from which you can extract any kind of
> element ('v', which was 'Char') and parse it into arbitrary types (the
> original parameter 'a'). For example, with this you could parse, say, a
> recursive algebraic data structure into something else.
> 
>     Nhc98 wouldn't take it. I assume this is NOT proper Haskell. The
> questions are: Is this doable? If so, how? Is this not recommendable? If
> not, why?