-
Notifications
You must be signed in to change notification settings - Fork 14
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
Comments
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 |
yes that would also be a valid function to exist. I think we should have both, what you think about names tho, What you mean by |
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. |
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. |
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? |
Ping |
@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 |
What think about adding something like this:
The text was updated successfully, but these errors were encountered: