Things and limitations...

Juan Carlos Arevalo Baeza
Wed, 16 May 2001 19:20:00 -0700

At 04:50 PM 5/15/2001 +1200, Tom Pledger wrote:

>  | ---
>  | 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)]
>  | ---
>The `SuitableCollection' class is pretty hard to define, though.
>Either it constrains its members to be list-shaped, or it prevents you
>from reusing functions like `item'.  Hmmm... I think I've just
>stumbled across your reason for treating Parser as a class.
>When the input isn't list-shaped, is the activity still called
>parsing?  Or is it a generalised fold (of the input type) and unfold
>(of the result type)?

    Well, it looks like Justin's answer to my "Databases" thread gave me 
the clue. What I want is called "Multiple parameter classes". Okasaki's 
code for implementing sets uses this extension to make a Set class. It 
wouldn't compile with nhc98 either, so I tried Hugs, which does support it 
if extensions are enabled, and has, in its documentation, a very nice 
explanation of the tradeoffs that using this extension entails.

    So, what I really want is something like:

class (MonadPlus (p s v)) => Parser p s v | s -> v 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 haven't had the time to play with this yet, but it sounds promising...

    In case anyone is interested in the Hugs documentation of the feature:


Juan Carlos "JCAB" Arevalo Baeza    |
Senior Technology programmer        |
Ronin Entertainment                 | ICQ: 10913692
                        (my opinions are only mine)
JCAB's Rumblings: