This is a question about the library of parsing combinators which
comes with the hbc compiler.

The library includes the definition of a class, $Token$, with the
following signature:

>class (Text a) => Token a where {
>    compareT   :: a -> a -> OrderedT;
>    stringT    :: a -> String;
>    positionT  :: a -> String;
>    eqT        :: a -> a -> Bool
>    }

where $OrderedT$ is defined by

>data OrderedT = LtT | GtT | EqT | UnT deriving (Eq)


The parsing combinators can only be used to parse lists of Tokens
(fair enough). The problem (for me) is that I don't know what the
class means (I don't have access to the source). I guessed that:

1.) $compareT$ is used to order tokens according to the likelihood of
    their appearance.

2.) $stringT$ converts a token to a string.

3.) $eqT$ is just a standard equality test (this guess is very shaky).

I have no idea of the intended meaning of $positionT$.

I used my guesses to define the following stubs:

>instance Token Char where
>       compareT x y    | x<y           = LtT           -- probably ok
>                       | x>y           = GtT
>                       | x==y          = EqT
>                       | otherwise     = UnT
>
>       stringT x                       = [x]           -- probably ok
> 
>       eqT                             = (==)          -- a bad guess
>
>       positionT                       = stringT       -- a cop-out


(I want to parse a list of characters.)

Obviously, this is rather unsatisfactory, and I *think* that it might
be affecting the parser I've written; it seems to work but it's very
very slow. I know, by the way, that parsers written using combinators
can exhibit strange space-time consumption; it's also fairly likely
that I've made a mistake. Whatever the cause of my problems is, it
would be nice to get the interpretation of $Token$ cleared up; if
anyone should answer my question then I will greatly apreciate it.

thanks,

balan

--------------------------------------------------------------------------
balan muthurajah                                       [EMAIL PROTECTED]
QMW College, London
--------------------------------------------------------------------------

Reply via email to