lens
Copyright(C) 2014-2026 Edward Kmett
LicenseBSD-style (see the file LICENSE)
MaintainerEdward Kmett <ekmett@gmail.com>
Stabilityprovisional
Portabilitynon-portable
Safe HaskellTrustworthy
LanguageHaskell2010

Control.Monad.Primitive.Lens

Description

ReifiedIsos witnessing the isomorphisms offered by Control.Monad.Primitive.

The generic conversion between two PrimBase monads that share a PrimState (that is, primToPrim or liftPrim) is not given its own name here: it is simply prim composed with its own reverse. See prim.

The unsafe* conversions in Control.Monad.Primitive are deliberately omitted: they coerce between monads with different PrimState tokens, and so do not form lawful ReifiedIsos.

Synopsis

Documentation

prim :: PrimBase m => Iso (m a) (m b) (State# (PrimState m) -> (# State# (PrimState m), a #)) (State# (PrimState m) -> (# State# (PrimState m), b #)) Source #

An ReifiedIso between a PrimBase monad and its underlying primitive state-transformer representation.

view prim ≡ internal
review prim ≡ primitive

Composing this ReifiedIso with its own reverse is the bidirectional PrimBase-to-PrimBase specialization of primToPrim (or liftPrim), converting directly between any two PrimBase monads that share a PrimState token. st and io compose the same way.

prim . from prim
  :: (PrimBase m, PrimBase n, PrimState m ~ PrimState n)
  => ReifiedIso (m a) (m b) (n a) (n b)
>>> (pure 5 :: ST RealWorld Int) ^. prim . from prim :: IO Int
5

st :: PrimBase m => Iso (m a) (m b) (ST (PrimState m) a) (ST (PrimState m) b) Source #

An ReifiedIso between a PrimBase monad and the ST monad with the same state token.

view st ≡ primToST
review st ≡ stToPrim
>>> (pure 5 :: IO Int) ^. st . io
5

io :: (PrimBase m, PrimState m ~ RealWorld) => Iso (m a) (m b) (IO a) (IO b) Source #

An ReifiedIso between a PrimBase monad whose state token is RealWorld and IO.

view io ≡ primToIO
review io ≡ ioToPrim
>>> (pure 5 :: ST RealWorld Int) ^. io
5