-
Notifications
You must be signed in to change notification settings - Fork 24
Open
Description
forgive :: (Given a => result) -> (a -> result)
forgive f a = give a fI find it useful for this kind of coding style:
type Pure xx a = Given (a -> IO xx)
newtype Managed a where
Managed :: (forall xx. Pure xx a => IO xx) -> Managed a
implPure :: forall xx a. Pure xx a => a -> IO xx
implPure = given
instance Functor Managed where
fmap :: forall a a'. (a -> a') -> (Managed a -> Managed a')
fmap f (Managed ma) = Managed ma' where
ma' :: forall xx. Pure xx a' => IO xx
ma' = ma `forgive`
\a -> implPure @xx (f a)
instance Applicative Managed where
pure :: a -> Managed a
pure x = Managed (given x)
(<*>) :: forall a b. Managed (a -> b) -> Managed a -> Managed b
Managed mf <*> Managed ma = Managed mb where
mb :: forall zz. Pure zz b => IO zz
mb = mf @zz `forgive` \f
-> ma @zz `forgive` \(a :: a)
-> implPure @zz @b (f a)Metadata
Metadata
Assignees
Labels
No labels