stateful-mtl-1.0.7: Typeclass instances for monad transformer stacks with an ST thread at the bottom.

Control.Monad.ST.Class

Description

This module contains the MonadST type class, which encapsulates a monad capable of lifting an ST computation. This type class is only intended to be implemented by the ST monad and any stack of monad transformers over an ST monad.

Presence of a MonadST instance implies that

  • The monad is single-threaded: performing an ST computation will not cause loss of referential transparency, and only one copy of its state thread will be available at any time.
  • Monad transformers can demand an underlying MonadST instance and use its state thread for their own safe computation in the ST monad.

Note: Most monad type classes cannot pass instances up through any instance of MonadTrans, because a transformer farther out may wish to override the inner instance. However, in MonadST we very specifically only want one state thread for any stack of transformers, and specifically one at the very bottom level. This justifies the very general MonadST propagation instance, (MonadST m, MonadTrans t, Monad m, Monad (t m)) => MonadST (t m) (not shown in Haddock for unknown reasons).

Do not implement MonadST propagation if you also provide a MonadTrans instance.

Synopsis

Documentation

class MonadST m whereSource

Type class of monads that can perform lifted computation in the ST monad.

Associated Types

type StateThread m Source

The type of the state thread used in this monad, never actually instantiated.

Methods

liftST :: ST (StateThread m) a -> m aSource

Instances

MonadST IO 
(MonadST m, MonadTrans t, Monad m) => MonadST (t m) 
MonadST (ST s)