ekmett / profunctors

Haskell 98 Profunctors
http://hackage.haskell.org/package/profunctors
Other
70 stars 43 forks source link

instance Applicative (Cayley f pro a) #108

Closed Icelandjack closed 8 months ago

Icelandjack commented 8 months ago

I was using Cayley to derive binary instances for Signal (url)

newtype Signal a b = Signal (Finalizer -> IO (a -> IO b))
  deriving
    ( Profunctor, Strong, Costrong, Choice
    , Category, Arrow, ArrowChoice, ArrowLoop, ArrowPlus, ArrowZero
    )
  via Cayley (Kleisli IO Finalizer) (Kleisli IO)

However to derive Applicative or Alternative, I need to use explicit Compose instead of reusing the same type for unary and binary instances:

  deriving (Functor, ..)    via Cayley (Kleisli IO Finalizer) (Kleisli IO) a
  deriving (Profunctor, ..) via Cayley (Kleisli IO Finalizer) (Kleisli IO)

I think it makes sense to derive the instances for Cayley so I can use Cayley (Kleisli IO Finalizer) (Kleisli IO) a for unary instances as well!

deriving via Compose f (pro a :: Type -> Type)
  instance (Functor f, Functor (pro a)) => Functor (Cayley f pro a)
deriving via Compose f (pro a :: Type -> Type)
  instance (Applicative f, Applicative (pro a)) => Applicative (Cayley f pro a)
deriving via Compose f (pro a :: Type -> Type)
  instance (Alternative f, Applicative (pro a)) => Alternative (Cayley f pro a)
deriving via Compose f (pro a :: Type -> Type)
  instance (Foldable f, Foldable (pro a)) => Foldable (Cayley f pro a)
instance (Traversable f, Traversable (pro a)) => Traversable (Cayley f pro a) where
  ..
RyanGlScott commented 8 months ago

The Functor, Foldable, and Traversable instances were added in 4af782eb86f092f8880890facaef8c1880b3c7a2. The only missing ones (AFAICT) are Applicative and Alternative.