Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add lift for Compose #20

Open
safareli opened this issue Mar 26, 2019 · 7 comments
Open

add lift for Compose #20

safareli opened this issue Mar 26, 2019 · 7 comments
Labels
type: enhancement A new feature or addition.

Comments

@safareli
Copy link

What think about adding something like this:

liftC :: forall f g. Functor f => Applicative g => f ~> Compose f g
liftC = map pure >>> Compose
@garyb
Copy link
Member

garyb commented Mar 27, 2019

Is there a reason to prefer that to

liftC :: forall f g. Applicative f => Functor g => g ~> Compose f g
liftC = Compose <<< pure

? 😉

(I mean, for your use case I'm sure there is, just saying in general I'm not sure there's an obvious choice here). I suppose there's an opportunity for another Inject here too perhaps.

@safareli
Copy link
Author

yes that would also be a valid function to exist. I think we should have both, what you think about names tho, lift, liftUp?

What you mean by Inject btw?

@garyb
Copy link
Member

garyb commented Mar 28, 2019

I mean you could have a class based function that chooses which of these functions to use based on the type, using an instance chain.

@safareli
Copy link
Author

ah you mean something like this https://github.com/purescript/purescript-either/blob/v4.1.1/src/Data/Either/Inject.purs#L8-L10

that would be even better.

@safareli
Copy link
Author

safareli commented Sep 11, 2019

Here it is:

class Lift f g where
  lift :: f ~> g

instance liftReflexive :: Lift a a where
  lift = identity

else instance liftLeft :: (Functor f, Applicative g) => Lift f (Compose f g) where
  lift = Compose <<< map pure

else instance liftRight :: (Applicative g, Lift f h) => Lift f (Compose g h) where
  lift = Compose <<< pure <<< lift


lift1 :: Identity ~> Compose (Either Unit) (Compose Maybe (Compose (Const Unit) Identity))
lift1 = lift

lift2 :: Identity ~> Compose (Either Unit) (Compose Identity (Compose (Const Unit) Maybe))
lift2 = lift

lift3 :: Identity ~> Compose Identity (Compose (Either Unit) (Compose (Const Unit) Maybe))
lift3 = lift

-- This compiles too but I guess Inject of Either will have same issue, and it's ok?
lift4 :: Identity ~> Compose Identity (Compose Identity (Compose (Const Unit) Maybe))
lift4 = lift

-- this will fail with  ERROR: No type class instance was found for Lift Identity Maybe
lift4 :: Identity ~> Compose Maybe (Compose (Either Unit) (Compose (Const Unit) Maybe))
lift4 = lift

Where should we add this, to Data.Functor.Compose or Data.Functor.Compose.Inject or Data.Functor.Compose.Lift?

@safareli
Copy link
Author

Ping

@JordanMartinez
Copy link
Contributor

@garyb Should we get this in before v0.14.0? It's not breaking, but seems trivial to do.

I think we might want to rename the lift1 functions to liftC1 so one can use both liftC2 from here and lift2 from Apply in the same file.

@JordanMartinez JordanMartinez added the type: enhancement A new feature or addition. label Dec 4, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: enhancement A new feature or addition.
Projects
None yet
Development

No branches or pull requests

3 participants