[Haskell-cafe] Alex Lexer: Trying to get rid of "Alex"
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?
Are you sure about the type of a?
It looks like you are using the "monad" wrapper, described here:
If that is true, then:
alexGetInput :: Alex AlexInput
type AlexInput = (AlexPosn, Char, String)
>From that we can infer from your code:
getEndPosition :: Alex AlexPosn
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
runAlex :: String -> Alex a -> Either String a
More information about the Haskell-Cafe