Skip to content

Add oneShot to Codensity instances #78

@Icelandjack

Description

@Icelandjack

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)
    (>>) = (*>)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions