can/should Functor have a quantified coercible constraint?

David Feuer david.feuer at gmail.com
Sun Jan 3 17:08:46 UTC 2021


Mag uses the One it does for efficiency/compactness. Coercible constraints
aren't unpacked in data constructors, sadly. If you're looking for more
examples of slightly-invalid but useful Functors, the first place I'd check
(beyond the very-Mag-like things in lens that inspired Mag) is Roman
Cheplyaka's regex-applicative. I don't know if his lifts coercions or not
(haven't looked in a while) but it does some similarly illegitimate things
for good reasons.

On Sun, Jan 3, 2021, 12:03 PM Oleg Grenrus <oleg.grenrus at iki.fi> wrote:

>     Prelude Control.Monad.Trans.State> :i StateT
>     type role StateT nominal representational nominal
>
> Note, `StateT` is nominal in last argument (a). Thus if (forall c d.
> Coercible ...) where a Functor superclass, Functor (and thus Monad)
> wouldn't be definable for StateT. That would be... unfortunate.
>
> Until there are "higher roles" Functor cannot be Coercible1. It would rule
> very simple code.
> (OTOH Mag can be repaired,
> https://oleg.fi/gists/posts/2019-07-31-fmap-coerce-coerce.html#functor-should-be-parametric
> ).
>
> - Oleg
>
> On 3.1.2021 18.31, Carter Schonwald wrote:
>
> Hey David,
> could you exposit what would go wrong? a concrete proof witness or
> explanation would help me a lot. other people might benefit too.
>
>
> for the stateT s Maybe a, perhaps i'm still waking up this AM, so let me
> try
> newtype StateT s m a = StateT {runStateT :: s -> m (a, s)}
>
> so this should expand to
> '(s -> Maybe (a,s)),'
> but the coerce would be on the 'a' here ... so i'm not seeing the issue?
>
>
>
> the latter example seem to boil down to "a free appplicative/functor Gadt"
> with some extra bits, though i've not worked through to seeing the unsafety
> for the latter examples, the definitions are the following :
>
> traverseBia <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#traverseBia> :: (Traversable t <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090275>, Biapplicative <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Biapplicative> p <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090274>)            => (a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090273> -> p <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090274> b <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090272> c <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090271>) -> t <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090275> a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090273> -> p <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090274> (t <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090275> b <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090272>) (t <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090275> c <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090271>)traverseBia <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#traverseBia> = inline (traverseBiaWith <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#traverseBiaWith> traverse)
>  --------traverseBiaWith <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#traverseBiaWith> :: forall p <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090289> a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090288> b <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090285> c <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090284> s <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090287> t <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090286>. Biapplicative <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Biapplicative> p <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090289>  => (forall f <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090291> x <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090290>. Applicative f <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090291> => (a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090288> -> f <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090291> x <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090290>) -> s <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090287> -> f <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090291> (t <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090286> x <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090290>))  -> (a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090288> -> p <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090289> b <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090285> c <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090284>) -> s <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090287> -> p <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090289> (t <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090286> b <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090285>) (t <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090286> c <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090284>)traverseBiaWith <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#traverseBiaWith> trav <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089877> p <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089876> s <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089875> = smash <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#smash> p <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089876> (trav <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089877> One <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#One> s <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089875>)
> -------smash <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#smash> :: forall p <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090262> t <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090258> a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090261> b <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090260> c <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090259>. Biapplicative <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Biapplicative> p <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090262>      => (a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090261> -> p <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090262> b <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090260> c <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090259>)      -> (forall x <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090264>. Mag <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Mag> a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090261> x <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090264> (t <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090258> x <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090264>))      -> p <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090262> (t <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090258> b <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090260>) (t <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090258> c <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090259>)smash <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#smash> p <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089872> m <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089871> = go <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089870> m <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089871> m <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089871>  where    go <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089870> :: forall x <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090249> y <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090248>. Mag <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Mag> a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090261> b <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090260> x <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090249> -> Mag <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Mag> a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090261> c <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090259> y <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090248> -> p <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090262> x <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090249> y <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090248>    go <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089870> (Pure <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Pure> t <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089868>) (Pure <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Pure> u <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089867>) = bipure <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#bipure> t <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089868> u <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089867>    go <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089870> (Map <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Map> f <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089865> x <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089864>) (Map <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Map> g <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089863> y <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089862>) = bimap f <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089865> g <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089863> (go <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089870> x <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089864> y <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089862>)    go <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089870> (Ap <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Ap> fs <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089860> xs <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089859>) (Ap <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Ap> gs <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089858> ys <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089857>) = go <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089870> fs <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089860> gs <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089858> <<*>> <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#%3C%3C%2A%3E%3E> go <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089870> xs <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089859> ys <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089857>
> #if MIN_VERSION_base(4,10,0)    go <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089870> (LiftA2 <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#LiftA2> f <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089855> xs <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089854> ys <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089853>) (LiftA2 <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#LiftA2> g <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089852> zs <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089851> ws <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089850>) = biliftA2 <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#biliftA2> f <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089855> g <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089852> (go <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089870> xs <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089854> zs <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089851>) (go <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089870> ys <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089853> ws <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089850>)
> #endif    go <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089870> (One <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#One> x <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089849>) (One <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#One> _) = p <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089872> x <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089849>    go <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089870> _ _ = impossibleError <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#impossibleError>
>
> ---- and then the magma is -- This is used to reify a traversal for 'traverseBia'. It's a somewhat-- bogus 'Functor' and 'Applicative' closely related to 'Magma' from the-- @lens@ package. Valid traversals don't use (<$), (<*), or (*>), so-- we leave them out. We offer all the rest of the Functor and Applicative-- operations to improve performance: we generally want to keep the structure-- as small as possible. We might even consider using RULES to widen lifts-- when we can:----   liftA2 f x y <*> z ==> liftA3 f x y z,---- etc., up to the pointer tagging limit. But we do need to be careful. I don't-- *think* GHC will ever inline the traversal into the go function (because that-- would duplicate work), but if it did, and if different RULES fired for the-- two copies, everything would break horribly.---- Note: if it's necessary for some reason, we *could* relax GADTs to-- ExistentialQuantification by changing the type of One to----   One :: (b -> c) -> a -> Mag a b c---- where the function will always end up being id. But we allocate a *lot*-- of One constructors, so this would definitely be bad for performance.data Mag <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Mag> a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089846> b <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089845> t <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089844> where  Pure <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Pure> :: t <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090197> -> Mag <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Mag> a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090196> b <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090195> t <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090197>  Map <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Map> :: (x <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089843> -> t <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090218>) -> Mag <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Mag> a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090217> b <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090216> x <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089843> -> Mag <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Mag> a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090217> b <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090216> t <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090218>  Ap <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Ap> :: Mag <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Mag> a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089842> b <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089841> (t <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089840> -> u <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089839>) -> Mag <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Mag> a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089842> b <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089841> t <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089840> -> Mag <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Mag> a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089842> b <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089841> u <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089839>
> #if MIN_VERSION_base(4,10,0)  LiftA2 <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#LiftA2> :: (t <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089838> -> u <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089837> -> v <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090187>) -> Mag <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Mag> a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090186> b <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090185> t <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089838> -> Mag <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Mag> a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090186> b <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090185> u <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089837> -> Mag <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Mag> a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090186> b <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090185> v <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090187>
> #endif  One <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#One> :: a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090256> -> Mag <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Mag> a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090256> b <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090255> b <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679090255>instance Functor (Mag <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Mag> a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089836> b <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089835>) where  fmap = Map <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Map>instance Applicative (Mag <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Mag> a <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089829> b <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#local-6989586621679089828>) where  pure = Pure <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Pure>  (<*>) = Ap <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#Ap>
> #if MIN_VERSION_base(4,10,0)  liftA2 = LiftA2 <https://hackage.haskell.org/package/bifunctors-5.5.9/docs/src/Data.Biapplicative.html#LiftA2>
> #endif
>
>
>
> On Sun, Jan 3, 2021 at 11:09 AM David Feuer <david.feuer at gmail.com> wrote:
>
>> You're not being very imaginative at all. Try out, oh, `StateT s Maybe`.
>> Or play around with a nice fake functor like the magma used to implement
>> `traverseBia` in `bifunctors`—pretty sure that won't work out.
>>
>> On Sun, Jan 3, 2021, 11:00 AM Carter Schonwald <
>> carter.schonwald at gmail.com> wrote:
>>
>>> Hey everyone!
>>>
>>> for context, I have some code where I was seeing how far coerce lets me
>>> go to avoid doing wrappers for certain codes,
>>>
>>> i found i had to write the following (mapping an operation over to its
>>> newtyped sibling)
>>>
>>> ```
>>> -- > :t QRA.wither
>>> --- forall a b f . Applicative f => (a -> f (Maybe b)) -> RAList a -> f
>>> (RAList b)
>>> ---
>>> wither :: forall a b f . (Applicative f, (forall c d .  Coercible c d =>
>>> Coercible (f c) (f d))  ) =>
>>>         (a -> f (Maybe b)) -> RAList a -> f (RAList b)
>>> wither = \f la ->    coerce     $ QRA.wither f $ coerce la
>>> ```
>>>
>>> i'd much rather be able to write
>>> ```
>>> wither :: forall a b f . (Applicative f) =>
>>>         (a -> f (Maybe b)) -> RAList a -> f (RAList b)
>>> wither = \f la ->    coerce     $ QRA.wither f $ coerce la
>>> ```
>>>
>>>
>>> this seems like it'd be best done via something like changing the
>>> functor class definition to
>>>
>>> ```
>>> class (forall c d .  Coercible c d => Coercible (f c) (f d))  ) =>
>>> Functor f where ..
>>> ```
>>>
>>> is there any specific reason why this is not feasible? I cant think of a
>>> GADT where this wouldn't be totally safe to do (because unlike in foldable,
>>> f is in both the domain and co-domain), but maybe i'm not being imaginative
>>> enough?
>>>
>>> look forward to learning what our obstacles are to making this happen
>>> for ghc 9.2 :)
>>>
>>> -Carter
>>>
>>> _______________________________________________
>>> Libraries mailing list
>>> Libraries at haskell.org
>>> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>>>
>>
> _______________________________________________
> Libraries mailing listLibraries at haskell.orghttp://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
> _______________________________________________
> Libraries mailing list
> Libraries at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/libraries
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/libraries/attachments/20210103/57bd3813/attachment-0001.html>


More information about the Libraries mailing list