The IOSim s Monad has the same instances as Codensity (SimA s) except with oneShot. Could be added to the Codensity instances, giving the compiler better hints and allowing the io-sim library to derive via Codensity.
newtype IOSim s a = IOSim { unIOSim :: forall r. (a -> SimA s r) -> SimA s r }
instance Functor (IOSim s) where
{-# INLINE fmap #-}
fmap f = \d -> IOSim $ oneShot $ \k -> unIOSim d (k . f)
instance Applicative (IOSim s) where
{-# INLINE pure #-}
{-# INLINE (<*>) #-}
{-# INLINE (*>) #-}
pure = \x -> IOSim $ oneShot $ \k -> k x
(<*>) = \df dx -> IOSim $ oneShot $ \k -> unIOSim df (\f -> unIOSim dx (\x -> k (f x)))
(*>) = \dm dn -> IOSim $ oneShot $ \k -> unIOSim dm (\_ -> unIOSim dn k)
instance Monad (IOSim s) where
{-# INLINE (>>=) #-}
{-# INLINE (>>) #-}
return = pure
(>>=) = \dm f -> IOSim $ oneShot $ \k -> unIOSim dm (\m -> unIOSim (f m) k)
(>>) = (*>)
The
IOSim s
Monad has the same instances asCodensity (SimA s)
except withoneShot
. Could be added to theCodensity
instances, giving the compiler better hints and allowing the io-sim library to derive viaCodensity
.