Hi, 

I have a problem with defining a new monad based on the state monad ST.
The new monad is a combination of ST and the Maybe monad. It is intended for
computations that use many states and may fail. If a part of the computation
fails the whole computation fails. (I want to use it for type inference).

newtype TIM s a = TIM (ST s (Maybe a))

Defining the Monad and MonadPlus instance and lifting the variable access
functions is straightforward.

However, I don't know how to define a function runTIM similar to runST which
executes the monad. The obvious definition

runTIM :: (forall s. TIM s a) -> Maybe a
runTIM (TIM m) = runST m

is rejected by both hugs -98 and ghc-4.03, because pattern matching on
polymorphic values is not permitted.

So, how can I define runTIM ???

-- 
OLAF CHITIL, Lehrstuhl fuer Informatik II, RWTH Aachen, 52056 Aachen, Germany
             Tel: (+49/0)241/80-21212; Fax: (+49/0)241/8888-217
             URL: http://www-i2.informatik.rwth-aachen.de/~chitil/



Reply via email to