Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

[Haskell-cafe] Alex Lexer: Trying to get rid of "Alex"

1 view
Skip to first unread message

Amit Deshwar

unread,
Feb 23, 2010, 4:16:10 AM2/23/10
to haskel...@haskell.org
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?

Thanks,

Amit Deshwar
University of Calgary

Bernie Pope

unread,
Feb 23, 2010, 4:59:19 AM2/23/10
to Amit Deshwar, haskel...@haskell.org
On 23 February 2010 20:15, Amit Deshwar <amit.d...@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.
_______________________________________________
Haskell-Cafe mailing list
Haskel...@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

0 new messages