Writing for both State and StateT

Derek Elkins ddarius86@hotmail.com
Tue, 22 Apr 2003 12:35:14 -0400


I had a similar problem, but that was because I needed to use the 
constructors.  MonadState has the methods you are using just write your code 
requiring MonadState as both State and StateT are instances.

next_random_probability :: ( ..., MonadState g m) => m a




>From: "Mark T.B. Carroll" <Mark.Carroll@Aetion.com>
>To: haskell-cafe@haskell.org
>Subject: Writing for both State and StateT
>Date: Tue, 22 Apr 2003 07:48:57 -0400 (EDT)
>
>At the moment I have code like,
>
>
>next_random_probability :: (RandomGen g, Num a, Random a) => State g a
>
>next_random_probability =
>     do old_rng <- get
>        let (random_probability, new_rng) = randomR (0, 1) old_rng
>        put new_rng
>        return random_probability
>
>next_random_probabilityT :: (RandomGen g, Num a, Random a, Monad m) => 
>StateT g m a
>
>next_random_probabilityT =
>     do old_rng <- get
>        let (random_probability, new_rng) = randomR (0, 1) old_rng
>        put new_rng
>        return random_probability
>
>
>Because these just use get and put which are both from MonadState, is it
>possible to write just one next_random_probability with a more general
>type signature, maybe mentioning MonadState, or at least two wrappers that
>call the same worker function, so that the same code is good for both
>State and StateT?
>
>-- Mark
>
>_______________________________________________
>Haskell-Cafe mailing list
>Haskell-Cafe@haskell.org
>http://www.haskell.org/mailman/listinfo/haskell-cafe


_________________________________________________________________
Protect your PC - get McAfee.com VirusScan Online  
http://clinic.mcafee.com/clinic/ibuy/campaign.asp?cid=3963