Daniel Fischer wrote:
getNumber :: String -> AssignedNumbers -> (Int,AssignedNumbers)

Yeah, that screams State Monad.


Hi, thanks for all the advice.

I was hoping my AssignedNumbers "class" would be useful with many data structures. In other words I would have

data State1 = State1 { a :: AssignedNumbers, b :: AssignedNumbers, ... }
data State2 = State2 { c :: AssignedNumbers, d :: AssignedNumbers, ... }

func1 :: State State1 Int
func1 = do
   ... something using a and b ...

func2 :: State State2 Int
func2 = do
   ... something using c and d ...

So I thought maybe I could defined a function like

nextNumber :: MonadState s m => (s -> AssignedNumbers) -> (AssignedNumbers -> s) -> m Int
nextNumber retreive putBack = ...

and have it be useful in both "State State1 a" and "State State2 a" monads, but defining the retrieve and putBack functions isn't pretty.

I will try to grok Robert's reply also. Maybe he has something addressing this.

Mike
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to