úÎ!ásÕË      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢£¤¥¦§¨©ª«¬­®¯°±²³´µ¶·¸¹º»¼½¾¿ÀÁÂÃÄÅÆÇÈÉÊ(c) Andrey Mokhov 2018-2019MIT (see the file LICENSE)andrey.mokhov@gmail.com experimentalNone4MPië! selectiveComposition of a functor f with the Ë monad. selective”Selective instance for the standard applicative functor Validation. This is a good example of a non-trivial selective functor which is not a monad. selective?Static analysis of selective functors with under-approximation. selective>Static analysis of selective functors with over-approximation.  selectiveAny monad can be given a  instance by defining  = S. This data type captures this pattern, so you can use it in combination with the  DerivingVia extension as follows: _newtype V1 a = V1 a deriving (Functor, Applicative, Selective, Monad) via SelectM Identity  selective'Any applicative functor can be given a  instance by defining  = S. This data type captures this pattern, so you can use it in combination with the  DerivingVia extension as follows: _newtype Over m a = Over m deriving (Functor, Applicative, Selective) via SelectA (Const m)  selective7A list of values, equipped with a fast membership test. selective1Selective applicative functors. You can think of B as a selective function application: when given a value of type Ì a, you  must apply' the given function, but when given a Í b, you may skip= the function and associated effects, and simply return the b.ÿ Note that it is not a requirement for selective functors to skip unnecessary effects. It may be counterintuitive, but this makes them more useful. Why? Typically, when executing a selective computation, you would want to skip the effects (saving work); but on the other hand, if your goal is to statically analyse a given selective computation and extract the set of all possible effects (without actually executing them), then you do not want to skip any effects, because that defeats the purpose of static analysis.The type signature of  is reminiscent of both Î and Ïd, and indeed a selective functor is in some sense a composition of an applicative functor and the Ë monad.Laws: Identity: #x <*? pure id = either id id <$> x Distributivity; note that y and z have the same type  f (a -> b): 7pure x <*? (y *> z) = (pure x <*? y) *> (pure x <*? z) Associativity: ‹x <*? (y <*? z) = (f <$> x) <*? (g <$> y) <*? (h <$> z) where f x = Right <$> x g y = a -> bimap (,a) ($a) y h z = uncurry z Monadic / (for selective functors that are also monads): select = selectM %There are also a few useful theorems:$Apply a pure function to the result: 8f <$> select x y = select (fmap f <$> x) (fmap f <$> y) Apply a pure function to the Left case of the first argument: 2select (first f <$> x) y = select x ((. f) <$> y) -Apply a pure function to the second argument: ?select x (f <$> y) = select (first (flip f) <$> x) ((&) <$> y) Generalised identity: !x <*? pure y = either y id <$> x A selective functor is rigid if it satisfies Î = . The following  interchange( law holds for rigid selective functors:  x *> (y <*? z) = (x *> y) <*? z If f is also a Ð, we require that  = , from which one can prove Î = . selectiveAn operator alias for S, which is sometimes convenient. It tries to follow the notational convention for Ñ« operators. The angle bracket pointing to the left means we always use the corresponding value. The value on the right, however, may be skipped, hence the question mark. selectiveThe ) function is a natural generalisation of Á: instead of skipping an unnecessary effect, it chooses which of the two given effectful functions to apply to a given argument; the other effect is unnecessary. It is possible to implement  in terms of +, which is a good puzzle (give it a try!).We can also implement  via : aselectB :: Selective f => f (Either a b) -> f (a -> b) -> f b selectB x y = branch x y (pure id)  selective3We can write a function with the type signature of  using the Ñ type class, but it will always execute the effects associated with the second argument, hence being potentially less efficient. selective!Recover the application operator Î from . Rigid$ selective functors satisfy the law Î = J and furthermore, the resulting applicative functor satisfies all laws of Ñ: Identity: pure id <*> v = v Homomorphism: pure f <*> pure x = pure (f x) Interchange: u <*> pure y = pure ($y) <*> u Composition: '(.) <$> u <*> v <*> w = u <*> (v <*> w) selective#One can easily implement a monadic % that satisfies the laws, hence any Ð is . selective8Branch on a Boolean value, skipping unnecessary effects.Ò selectiveEliminate a specified value a from f (Either a b) by replacing it with a given f b. selective;The list of all possible values of an enumerable data type. selectiveEmbed a list of values into 6 using the trivial but slow membership test based on Ó. selectiveEliminate all specified values a from f (Either a b)) by replacing each of them with a given f a. selectiveEliminate all specified values a from f (Either a b)) by replacing each of them with a given f a. selectiveAA restricted version of monadic bind. Fails with an error if the Ô and Õ instances for a do not cover all values of a. selective Conditionally perform an effect.  selectiveA lifted version of .! selectiveReturn the first Right value. If both are Left's, accumulate errors." selectiveAccumulate the Right values, or return the first Left.# selectiveSwap Left and Right.Ö selective*Append two semigroup values or return the Right one.$ selective4Keep checking an effectful condition while it holds.% selective9Keep running an effectful computation until it returns a Right value, collecting the Left's using a supplied Monoid instance.& selective$A lifted version of lazy Boolean OR.' selective%A lifted version of lazy Boolean AND.( selectiveA lifted version of ×). Retains the short-circuiting behaviour.) selectiveA lifted version of Ø). Retains the short-circuiting behaviour.* selective8Generalised folding with the short-circuiting behaviour.+  !"#$%&'()*+ !"%$&'*()  #4(c) Andrey Mokhov 2018-2019MIT (see the file LICENSE)andrey.mokhov@gmail.com experimentalNoneSXw ` selectiveFree selective functors.b selective1Lift a functor into a free selective computation.c selective$Given a natural transformation from f to g6, this gives a canonical natural transformation from Select f to g+. Note that here we rely on the fact that g is a lawful selective functor.d selective8Concatenate all effects of a free selective computation.e selective>Extract the resulting value if there are no necessary effects.f selectiveCollect all possible effects; in the order they appear in a free selective computation.g selectiveExtract all necessary effects; in the order they appear in a free selective computation.`abcdefg`abefgcd(c) Andrey Mokhov 2018-2020MIT (see the file LICENSE)andrey.mokhov@gmail.com experimentalSafe &'4PSUVX_»Ð&k selective;Handler of a single case in a generalised pattern matching ¢.n selectiveEA product type where the payload has the type specified with the tag.o selectiveNA generalised product type (Pi), which holds an appropriately tagged payload u x for every possible tag t x.eNote that this looks different than the standard formulation of Pi types. Maybe it's just all wrong!See ƒ,   and ¡ for an example.p selective5An alternative definition of monads, as witnessed by – and —. This class is almost like { but has no the constraint on t.r selectiveCAn alternative definition of applicative functors, as witnessed by ” and t. This class is almost like {! but has a strict constraint on t.u selective?Static analysis of selective functors with under-approximation.x selective>Static analysis of selective functors with over-approximation.{ selective_Multi-way selective functors. Given a computation that produces a value of a sum type, we can |> it to the corresponding computation in a given product type.For greater similarity with ¢-, we could have given the following type to |: /match :: f (Sigma t) -> (t ~> Case f a) -> f a $We chose to simplify it by inlining o and k.} selective'A class of tags that can be enumerated.IAn valid instance must list every tag in the resulting list exactly once. selective#Hide the type of the payload a tag.>There is a whole library dedicated to this nice little GADT:  'http://hackage.haskell.org/package/some. selective?A potentially uncountable collection of tags for the same unit () payload.ƒ selectiveA data type with two tags „ and …( that allows us to encode the good old Ë as ‰ ƒ, where the tags „ and … correspond to Ì and Í, respectively. See Œ and ' that witness the isomorphism between Ë a b and ‰ (ƒ a b).† selectiveCA data type with a single tag. This data type is commonly known as Refl, see Data.Type.Equality.ˆ selective)A data type defining no tags. Similar to   but parameterised.‰ selectiveA generalised sum type where tK stands for the type of constructor "tags". Each tag has a type parameter x. which determines the type of the payload. A ‰ t{ value therefore contains a payload whose type is not visible externally but is revealed when pattern-matching on the tag.See ƒ, Œ and  for an example.‹ selective2An injection into a generalised sum. An alias for ‰.Œ selectiveEncode Ë into a generalised sum type. selectiveDecode Ë from a generalised sum type. selectivebGeneralised pattern matching on a Sigma type using a Pi type to describe how to handle each case.This is a specialisation of ¢ for  f = Identity7. We could also have also given it the following type: 4matchPure :: Sigma t -> (t ~> Case Identity a) -> a $We chose to simplify it by inlining o, k and Ù. selective-The basic "if-then" selection primitive from Control.Selective.‘ selectiveChoose a matching effect with Ë.’ selective!Recover the application operator Î from |.“ selective%A restricted version of monadic bind.” selective!Recover the application operator Î from t.• selectiveEvery Ñ is also an r.– selective Monadic bind.— selective-Every monad is a multi-way selective functor.˜ selective(A projection from a generalised product.™ selective[A trivial product type that stores nothing and simply returns the given tag as the result.š selectiveáAs it turns out, one can compose such generalised products. Why not: given a tag, get the payload of the first product and then pass it as input to the second. This feels too trivial to be useful but is still somewhat cute.› selective\Update a generalised sum given a generalised product that takes care of all possible cases.œ selectiveAEncode a value into a generalised sum type that has a single tag †. selectiveADecode a value from a generalised sum type that has a single tag †.ž selectiveEEncode a value into a generalised product type that has a single tag †.Ÿ selectiveEDecode a value from a generalised product type that has a single tag †.  selectiveEncode (a, b)! into a generalised product type.¡ selectiveDecode (a, b)! from a generalised product type.¢ selectivebGeneralised pattern matching on a Sigma type using a Pi type to describe how to handle each case.8klmnopqrstuvwxyz{|}~€‚ƒ„…†‡ˆ‰Š‹ŒŽ‘’“”•–—˜™š›œžŸ ¡¢8‰Š‹ˆ†‡ƒ„…‚ŽŒ€}~{|xyzuvw‘’“rst”•pq–—on˜™š›œžŸ ¡klm¢o4(c) Andrey Mokhov 2018-2019MIT (see the file LICENSE)andrey.mokhov@gmail.com experimentalNone&'PSXÉG³ selectiveFree rigid selective functors.¶ selective1Lift a functor into a free selective computation.· selective$Given a natural transformation from f to g6, this gives a canonical natural transformation from Select f to g.¸ selective8Concatenate all effects of a free selective computation.¹ selective>Extract the resulting value if there are no necessary effects.º selectiveWCollect all possible effects in the order they appear in a free selective computation.» selective•Extract the necessary effect from a free selective computation. Note: there can be at most one effect that is statically guaranteed to be necessary. ³µ´¶·¸¹º» ³µ´¶¹º»·¸(c) Andrey Mokhov 2018-2019MIT (see the file LICENSE)andrey.mokhov@gmail.com experimentalNone&'4SXÕ3¿ selectiveFree rigid selective functors. selective1Lift a functor into a free selective computation.à selective$Given a natural transformation from f to g6, this gives a canonical natural transformation from Select f to g.Ä selective8Concatenate all effects of a free selective computation.Å selective>Extract the resulting value if there are no necessary effects.Æ selectiveWCollect all possible effects in the order they appear in a free selective computation.Ç selective•Extract the necessary effect from a free selective computation. Note: there can be at most one effect that is statically guaranteed to be necessary. ¿ÁÀÂÃÄÅÆÇ ¿ÁÀÂÅÆÇÃÄÚ      !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdeefghijklmnoopqrstuvwxyz{{||}~€€‚‚ƒ„…†‡#ˆ‰Š"‹ŒŽ‘’“”•–—˜™MNOPZ[\]^_`aešefghij›lmnešefghij›lmnœžœŸœ œ¡¢œ¡£œ¡¤œ¡¥¦œ§¨œ©ªœ©«¬œ§­œ§®œ¯°±&selective-0.4.1-DuDm58pOsFhJsrz4GwRP4hControl.SelectiveControl.Selective.FreeControl.Selective.MultiControl.Selective.Rigid.FreeControl.Selective.Rigid.Freer Data.Maybe fromMaybe Data.VoidVoid ComposeEither ValidationFailureSuccessUndergetUnderOvergetOverSelectM getSelectMSelectA getSelectACases Selectiveselect<*?branchselectAapSselectMifS casesEnumcasesmatchSmatchMbindSwhenS fromMaybeSorElseandAlso swapEitherwhileS untilRight<||><&&>anySallSfoldS$fSelectiveArrowMonad$fSelectiveWriterT$fSelectiveWriterT0$fSelectiveStateT$fSelectiveStateT0$fSelectiveRWST$fSelectiveRWST0$fSelectiveReaderT$fSelectiveMaybeT$fSelectiveIdentityT$fSelectiveExceptT$fSelectiveContT$fSelectiveSTM $fSelectiveST$fSelectiveProxy$fSelectiveNonEmpty$fSelectiveMaybe$fSelectiveIdentity$fSelectiveEither $fSelective->$fSelective(,) $fSelective[] $fSelectiveIO$fSelectiveCompose$fSelectiveProduct$fSelectiveZipList$fSelectiveLift$fSelectiveSelectA$fSelectiveSelectM$fSelectiveOver$fApplicativeOver$fSelectiveUnder$fApplicativeUnder$fSelectiveValidation$fApplicativeValidation$fAlternativeComposeEither$fApplicativeComposeEither$fFunctorSelectA$fApplicativeSelectA$fFunctorSelectM$fApplicativeSelectM$fMonadSelectM$fEqOver $fFunctorOver $fOrdOver $fShowOver $fEqUnder$fFunctorUnder $fOrdUnder $fShowUnder$fFunctorValidation$fShowValidation$fFunctorComposeEitherSelect liftSelect runSelect foldSelectgetPure getEffectsgetNecessaryEffects$fSelectiveSelect$fApplicativeSelect$fFunctorSelectCase handleCasePi~>MonadSmatchUnconstrained ApplicativeSpureAmatchOnematch Enumerable enumerateSomeManyTwoABOneZeroSigmainject eitherToSigma sigmaToEithermany matchPureapmatchAbindprojectidentitycomposeapplytoSigma fromSigmatoPifromPipairToPipiToPair matchCases$fEnumerableMany$fEnumerableTwo$fEnumerableOne$fEnumerableZeroPuregetNecessaryEffectbase Data.EitherEitherLeftRightGHC.Base<*>>>=Monad Applicative eliminate Data.FoldableelemGHC.EnumBoundedEnum appendLeftanyallData.Functor.IdentityIdentity