From c93d3a146b457650cc14ded0a7dd4a8572b29680 Mon Sep 17 00:00:00 2001 From: Andrey Mokhov Date: Thu, 3 Dec 2020 00:46:04 +0000 Subject: [PATCH] Add a note on skew associativity --- src/Control/Selective.hs | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) diff --git a/src/Control/Selective.hs b/src/Control/Selective.hs index af9e9ca..46c817d 100644 --- a/src/Control/Selective.hs +++ b/src/Control/Selective.hs @@ -141,6 +141,31 @@ import qualified Control.Monad.Trans.Writer.Strict as S class Applicative f => Selective f where select :: f (Either a b) -> f (a -> b) -> f b +{- Why do we have skew associativity, where we can reassociate effects to the + left but not to the right? + + The following two tables, which list all possible combinations of effect + execution and skipping, might give you some intuition on why this happens. + + --------------- + (x <*? y) <*? z + --------------- + 1 0 0 + 1 1 0 + 1 0 1 + 1 1 1 + + --------------- + x <*? (y <*? z) + --------------- + 1 0 0 + 1 1 0 + 1 1 1 + + A key observation is that when effects are associated to the right, we can't + skip the effect y and execute the effect z: combination 101 is impossible. +-} + -- | An operator alias for 'select', which is sometimes convenient. It tries to -- follow the notational convention for 'Applicative' operators. The angle -- bracket pointing to the left means we always use the corresponding value.