ekmett / ekmett/reflection

Provide flipped ‘give’

Open
#36 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
105
Forks
24
PR merge metrics
No merged PRs in 30d

Description

```haskell
forgive :: (Given a => result) -> (a -> result)
forgive f a = give a f
```

I find it useful for this kind of coding style:

```haskell
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)
```

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.