[Haskell-cafe] Alex Lexer: Trying to get rid of "Alex"
Bernie Pope
florbitous at gmail.com
Tue Feb 23 04:58:55 EST 2010
On 23 February 2010 20:15, Amit Deshwar <amit.deshwar at gmail.com> wrote:
> Hi Haskell-cafe
> My problem: I'm trying to obtain the current position of the lexer once it
> reaches the end of the file (line and row number).
> I'm trying to do this in a function:
> getEndPosition = do
> (a,b,c) <- alexGetInput
> return a
>
> Unfortunately, the type of a is 'Alex AlexPosn' instead of just 'AlexPosn'
> How do I strip the Alex so I'm left with just a AlexPosn object?
Hi Amit,
Are you sure about the type of a?
It looks like you are using the "monad" wrapper, described here:
http://www.haskell.org/alex/doc/html/wrappers.html
If that is true, then:
alexGetInput :: Alex AlexInput
and
type AlexInput = (AlexPosn, Char, String)
>From that we can infer from your code:
getEndPosition :: Alex AlexPosn
and thus:
a :: AlexPosn
If you want to manipulate the value bound to a, you can simply apply a
function to it in the body of getEndPosition, and return the result of
that application (still inside the Alex type). Or you can use the
function:
runAlex :: String -> Alex a -> Either String a
Cheers,
Bernie.
More information about the Haskell-Cafe
mailing list