input-output-hk / io-sim

Haskell's IO simulator which closely follows core packages (base, async, stm).
https://hackage.haskell.org/package/io-sim
Apache License 2.0
37 stars 15 forks source link

Provide PrimMonad for IOSim and add stToIO to MonadST #141

Closed dcoutts closed 8 months ago

dcoutts commented 8 months ago

Having IOSim be an instance of PrimMonad (and thus MonadPrim) opens up access to (almost) all of the functionality from the primitive package: including arrays, prim arrays, byte arrays, poiters etc.

The only thing from the primitive package that definately will not work is Data.Primitive.MVar, i.e. real MVars.

And then also use this to make MonadST a lot simpler. By using the PrimState type family we can express the type of stToIO properly:

stToIO :: MonadST m => ST (PrimState m) a -> m a

whereas using withLiftST was very tricky.