Skip to content

Instantly share code, notes, and snippets.

@viercc
Last active July 29, 2022 06:18
Show Gist options
  • Save viercc/af7a1ad114c2101a0a2983a37673cf26 to your computer and use it in GitHub Desktop.
Save viercc/af7a1ad114c2101a0a2983a37673cf26 to your computer and use it in GitHub Desktop.

Collection of "would-be co-Applicative" formulations

  1. Co-Applicative programming style (Haskell for all, by Gabriella Gonzalez
  2. Reddit post
  3. StackOverflow

In 1.

This article explains Divisible as a co-Applicative

In 2.

This reddit post discusses "Coapplicative".

OP proposed:

-- Poster (u/tailcalled) proposed
class (Functor f) => Coapplicative f where
  copure :: f a -> a
  cozip :: f (Either a b) -> Either (f a) (f b)

There was a comment on another formulation (which is very close to Decidable)

-- Comment by u/camcann
class (Contravariant f) => Inapplicative f where
    nil :: f Void
    contrazip :: (f a, f b) -> f (Either a b)

In 3.

The best answer explains there are no clear relation between CoApplicative and CoMonoidal, and they're also unrelated to Comonad.

(Contrary to the happy coincidence Applicative is also equivalent to lax monoidal Functor)

class Functor f => Applicative f where
    pure  :: a -> f a
    (<*>) :: f (a -> b) -> (f a -> f b)

class Functor f => Monoidal f where
    -- equivalent to Applicative
    unit :: () -> f ()
    zip  :: (f a, f b) -> f (a,b)

class Functor f => CoApplicative f where
    copure :: f a -> a
    coap   :: (f a -> f b) -> f (a -> b)

class Functor f => CoMonoidal f where
    -- NOT equivalent to CoApplicative
    counit :: f () -> ()
    cozip :: f (a,b) -> (f a, f b)

Another answer named Decisive.

class Functor f => Decisive f where
    nogood :: f Void -> Void
    orwell :: f (Either s t) -> Either (f s) (f t)

This class is also mentioned in 2. Sadly the link to the details in the answer is dead now.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment