[Haskell-cafe] Alex monadUserState question

Mihai Maruseac mihai.maruseac at gmail.com
Thu Feb 17 14:15:55 CET 2011


On Thu, Feb 17, 2011 at 2:42 PM, Simon Marlow <simonmar at microsoft.com> wrote:
>
>> Just downloaded the latest Alex package from Hackage (different from
>> the one in Ubuntu's repositories by 2 minor versions) and found that
>> the monadUserState wrapper still misses 2 functions for dealing with
>> changes in the user supplied state. Is this intended or it was an
>> unwanted omission?
>
> Could you tell me what's missing?  Is this a regression?
>

Yes, there are two functions (this is the type that I guess they should have)

getUserData :: Alex AlexUserState
setUserData :: AlexUserState -> Alex ()

I've used them in a particular implementation today in this way but
maybe there are other ways to handle them too.

He're the code I've used:

getUserData :: Alex AlexUserState
getUserData = Alex $ \s at AlexState{alex_ust=ud} -> Right (s, ud)

setUserData :: AlexUserState -> Alex ()
setUserData ust = Alex $ \s -> Right (s{alex_ust=ust}, ())

Thanks for the quick input,
-- 
Mihai



More information about the Haskell-Cafe mailing list