Skip to content

Provide flipped ‘give’ #36

@Icelandjack

Description

@Icelandjack
forgive :: (Given a => result) -> (a -> result)
forgive f a = give a f

I 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

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