[Haskell] State Transformers and Control.Monad.ST.Lazy

Vivian McPhail vivian.mcphail at paradise.net.nz
Sun Jun 20 22:55:22 EDT 2004


Hi,

>From the very helpful posts of John Hughes and others concerning 
"Monadic Loops",  I've been advised to re-implement my neural net 
simulator using lazy state threads to avoid crashes to which recursive 
(and tail-recursive) monads lead.

I had been using monad transformers to lift IO operations:

data NeuralNet = NN { ... }

data NNO a = NNO (NeuralNet -> (a,NeuralNet))

data NNT m a = NNT (NeuralNet -> m (a,NeuralNet)) 

following the example of a state transformer in "Functional Programming 
with Overloading and Higher-Order Polymorphism".

I am trying to reimplement with 

data ST s a

from Control.Monad.ST.Lazy and "Lazy Functional State Threads"

however there is something I think I do not understand, that is the "s" in 
the ST dataype.  The compiler tells me it needs to be instantiated, but I am 
presuming that a type such as

type NNST = ST NeuralNet a

is useless because there is no way (from this module) to access that 
state using the "update" method of the MonadState class.

1. Am I correct in thinking that I need to use a monad transformer lifting 
from the ST monad to incorporate my NeuralNet datatype

2. Can I merely instantiate ST as ST () a?

Thanks in advance.

Vivian McPhail


More information about the Haskell mailing list