Reputation: 2624
I have this global State
type GlobalState a = State Int a
but one function needs its own local state and access to the GlobalState
type LocalState a = State [String] a
But I'm not sure now to combine them.
Right now I just add local state to the global
type GlobalState a = State (Int, [String]) a
It works fine, but I don't think it's right because I only need local state in one function. Is there a better way?
Upvotes: 1
Views: 290
Reputation: 34391
You may use a monad stack of two State
s:
type LocalState a = [String]
type GlobalState a = [String]
newtype MyState a = StateT GlobalState (State LocalState) a
Upvotes: 2