planet-mitchell-0.0.0: Planet Mitchell

Safe HaskellNone
LanguageHaskell2010

Decidable

Contents

Synopsis

Decidable

class Divisible f => Decidable (f :: * -> *) where #

A Decidable contravariant functor is the contravariant analogue of Alternative.

Noting the superclass constraint that f must also be Divisible, a Decidable functor has the ability to "fan out" input, under the intuition that contravariant functors consume input.

In the dicussion for Divisible, an example was demonstrated with Serializers, that turn as into ByteStrings. Divisible allowed us to serialize the product of multiple values by concatenation. By making our Serializer also Decidable- we now have the ability to serialize the sum of multiple values - for example different constructors in an ADT.

Consider serializing arbitrary identifiers that can be either Strings or Ints:

data Identifier = StringId String | IntId Int

We know we have serializers for Strings and Ints, but how do we combine them into a Serializer for Identifier? Essentially, our Serializer needs to scrutinise the incoming value and choose how to serialize it:

identifier :: Serializer Identifier
identifier = Serializer $ identifier ->
  case identifier of
    StringId s -> runSerializer string s
    IntId i -> runSerializer int i

It is exactly this notion of choice that Decidable encodes. Hence if we add an instance of Decidable for Serializer...

instance Decidable Serializer where
  lose f = Serializer $ a -> absurd (f a)
  choose split l r = Serializer $ a ->
    either (runSerializer l) (runSerializer r) (split a)

Then our identifier Serializer is

identifier :: Serializer Identifier
identifier = choose toEither string int where
  toEither (StringId s) = Left s
  toEither (IntId i) = Right i

Minimal complete definition

lose, choose

Methods

lose :: (a -> Void) -> f a #

Acts as identity to choose.

choose :: (a -> Either b c) -> f b -> f c -> f a #

Instances
Decidable SettableStateVar 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> SettableStateVar a #

choose :: (a -> Either b c) -> SettableStateVar b -> SettableStateVar c -> SettableStateVar a #

Decidable Predicate 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> Predicate a #

choose :: (a -> Either b c) -> Predicate b -> Predicate c -> Predicate a #

Decidable Comparison 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> Comparison a #

choose :: (a -> Either b c) -> Comparison b -> Comparison c -> Comparison a #

Decidable Equivalence 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> Equivalence a #

choose :: (a -> Either b c) -> Equivalence b -> Equivalence c -> Equivalence a #

Decidable (U1 :: * -> *) 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> U1 a #

choose :: (a -> Either b c) -> U1 b -> U1 c -> U1 a #

Monoid r => Decidable (Op r) 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> Op r a #

choose :: (a -> Either b c) -> Op r b -> Op r c -> Op r a #

Decidable (Proxy :: * -> *) 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> Proxy a #

choose :: (a -> Either b c) -> Proxy b -> Proxy c -> Proxy a #

Divisible m => Decidable (MaybeT m) 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> MaybeT m a #

choose :: (a -> Either b c) -> MaybeT m b -> MaybeT m c -> MaybeT m a #

Divisible m => Decidable (ListT m) 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> ListT m a #

choose :: (a -> Either b c) -> ListT m b -> ListT m c -> ListT m a #

Decidable f => Decidable (Rec1 f) 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> Rec1 f a #

choose :: (a -> Either b c) -> Rec1 f b -> Rec1 f c -> Rec1 f a #

Decidable f => Decidable (Alt f) 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> Alt f a #

choose :: (a -> Either b c) -> Alt f b -> Alt f c -> Alt f a #

Decidable f => Decidable (IdentityT f) 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> IdentityT f a #

choose :: (a -> Either b c) -> IdentityT f b -> IdentityT f c -> IdentityT f a #

Decidable f => Decidable (Backwards f) 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> Backwards f a #

choose :: (a -> Either b c) -> Backwards f b -> Backwards f c -> Backwards f a #

Decidable m => Decidable (WriterT w m) 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> WriterT w m a #

choose :: (a -> Either b c) -> WriterT w m b -> WriterT w m c -> WriterT w m a #

Decidable m => Decidable (StateT s m) 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> StateT s m a #

choose :: (a -> Either b c) -> StateT s m b -> StateT s m c -> StateT s m a #

Decidable m => Decidable (StateT s m) 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> StateT s m a #

choose :: (a -> Either b c) -> StateT s m b -> StateT s m c -> StateT s m a #

Decidable m => Decidable (WriterT w m) 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> WriterT w m a #

choose :: (a -> Either b c) -> WriterT w m b -> WriterT w m c -> WriterT w m a #

Decidable f => Decidable (Reverse f) 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> Reverse f a #

choose :: (a -> Either b c) -> Reverse f b -> Reverse f c -> Reverse f a #

(Decidable f, Decidable g) => Decidable (f :*: g) 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> (f :*: g) a #

choose :: (a -> Either b c) -> (f :*: g) b -> (f :*: g) c -> (f :*: g) a #

(Decidable f, Decidable g) => Decidable (Product f g) 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> Product f g a #

choose :: (a -> Either b c) -> Product f g b -> Product f g c -> Product f g a #

Decidable m => Decidable (ReaderT r m) 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> ReaderT r m a #

choose :: (a -> Either b c) -> ReaderT r m b -> ReaderT r m c -> ReaderT r m a #

Decidable f => Decidable (M1 i c f) 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> M1 i c f a #

choose :: (a -> Either b c0) -> M1 i c f b -> M1 i c f c0 -> M1 i c f a #

(Applicative f, Decidable g) => Decidable (f :.: g) 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> (f :.: g) a #

choose :: (a -> Either b c) -> (f :.: g) b -> (f :.: g) c -> (f :.: g) a #

(Applicative f, Decidable g) => Decidable (Compose f g) 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> Compose f g a #

choose :: (a -> Either b c) -> Compose f g b -> Compose f g c -> Compose f g a #

Decidable m => Decidable (RWST r w s m) 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> RWST r w s m a #

choose :: (a -> Either b c) -> RWST r w s m b -> RWST r w s m c -> RWST r w s m a #

Decidable m => Decidable (RWST r w s m) 
Instance details

Defined in Data.Functor.Contravariant.Divisible

Methods

lose :: (a -> Void) -> RWST r w s m a #

choose :: (a -> Either b c) -> RWST r w s m b -> RWST r w s m c -> RWST r w s m a #

chosen :: Decidable f => f b -> f c -> f (Either b c) #

contramany :: Decidable f => f a -> f [a] #