[Haskell-cafe] Delaling with State StateT and IO in the same function

Kirsten Chevalier catamorphism at gmail.com
Mon Feb 26 18:34:53 EST 2007


On 2/26/07, Alfonso Acosta <alfonso.acosta at gmail.com> wrote:
> On 2/27/07, Kirsten Chevalier <catamorphism at gmail.com> wrote:
>
> > I may be missing something, but why are you using both State and
> > StateT? Maybe I don't understand your code, but it seems like you
> > could be using StateT everywhere you're currently using State.
>
> Well, as far as I know using "StateT s IO a" for the input functions
> would force the state and value of their monad to stay within IO. That
> restriction dissapears by using barely "State s a"

Ah, ok. So what if you changed your netlist function so that the type
sig would be:

netlist :: DT.Traversable f =>
          (State s (S HDPrimSignal) -> State s  v ) -> -- new
          (State s (Type,v) -> S v -> State s ())   -> -- define
          State s (f HDPrimSignal) ->                  -- the graph
          IO (State s ())

I didn't follow your code well enough to be sure that this would help,
but I think it might. Or why not:

netlist :: DT.Traversable f =>
          (State s (S HDPrimSignal) -> State s  v ) -> -- new
          (State s (Type,v) -> S v -> State s ())   -> -- define
          State s (f HDPrimSignal) ->                  -- the graph
          IO s

which seems to me like it would be even simpler, unless you're
planning on composing calls to netlist together (and from the code you
gave, I can't tell whether you are.)

If your code is such that refactoring it to have either of those types
wouldn't make sense, stating the reasons why should clarify things for
the rest of us.

Cheers,
Kirsten

-- 
Kirsten Chevalier* chevalier at alum.wellesley.edu *Often in error, never in doubt
"Aw, honey, you can keep what's in my pockets, but send me back my pants."
--Greg Brown


More information about the Haskell-Cafe mailing list