| Copyright | Conor McBride and Ross Paterson 2005, (c) 2015 KONISHI Yohsuke |
|---|---|
| License | BSD-style (see the LICENSE file in the distribution) |
| Maintainer | ocean0yohsuke@gmail.com |
| Stability | experimental |
| Portability | --- |
| Safe Haskell | Safe |
| Language | Haskell2010 |
DeepControl.Commutative
Contents
Description
This module is made of , distilling most function names polluted with action kind of concepts into crystalized(static) ones.Traversable
- class Functor c => Commutative c where
- commute :: Applicative f => c (f a) -> f (c a)
- cmap :: (Applicative f, Commutative c) => (a -> f b) -> c a -> f (c b)
- cfor :: (Applicative f, Commutative c) => c a -> (a -> f b) -> f (c b)
- fmapDefault :: Commutative t => (a -> b) -> t a -> t b
- foldMapDefault :: (Commutative t, Monoid m) => (a -> m) -> t a -> m
- sink2 :: (Commutative m1, Applicative m2, Applicative m3) => m1 (m2 (m3 a)) -> m2 (m3 (m1 a))
- float2 :: (Applicative m1, Commutative m2, Commutative m3) => m2 (m3 (m1 a)) -> m1 (m2 (m3 a))
- sink3 :: (Commutative m1, Applicative m2, Applicative m3, Applicative m4) => m1 (m2 (m3 (m4 a))) -> m2 (m3 (m4 (m1 a)))
- float3 :: (Applicative m1, Commutative m2, Commutative m3, Commutative m4) => m2 (m3 (m4 (m1 a))) -> m1 (m2 (m3 (m4 a)))
- sink4 :: (Commutative m1, Applicative m2, Applicative m3, Applicative m4, Applicative m5) => m1 (m2 (m3 (m4 (m5 a)))) -> m2 (m3 (m4 (m5 (m1 a))))
- float4 :: (Applicative m1, Commutative m2, Commutative m3, Commutative m4, Commutative m5) => m2 (m3 (m4 (m5 (m1 a)))) -> m1 (m2 (m3 (m4 (m5 a))))
- sink5 :: (Commutative m1, Applicative m2, Applicative m3, Applicative m4, Applicative m5, Applicative m6) => m1 (m2 (m3 (m4 (m5 (m6 a))))) -> m2 (m3 (m4 (m5 (m6 (m1 a)))))
- float5 :: (Applicative m1, Commutative m2, Commutative m3, Commutative m4, Commutative m5, Commutative m6) => m2 (m3 (m4 (m5 (m6 (m1 a))))) -> m1 (m2 (m3 (m4 (m5 (m6 a)))))
The Commutative class
class Functor c => Commutative c where Source
[], Maybe, Either, Except and Writer are all commutative each other. So these monads can be deepened to Monad2, Monad3, Monad4 and Monad5.
Methods
commute :: Applicative f => c (f a) -> f (c a) Source
This method is equivalent for except the name.
The only difference is the name "commute", that is to say from which no action kind of concepts smell.sequenceA
>>>commute $ Just [1][Just 1]>>>commute $ [Just 1]Just [1]
>>>commute $ Right (Just 1)Just (Right 1)>>>commute $ Just (Right 1)Right (Just 1)
Instances
| Commutative [] Source | |
| Commutative Maybe Source | |
| Commutative (Either a) Source | |
| Commutative (Const m) Source | |
| Commutative (Except e) Source | |
| Monoid w => Commutative (Writer w) Source | |
| (Commutative f1, Commutative f2) => Commutative (IdentityT2 f1 f2) Source | |
| (Commutative f1, Commutative f2, Commutative f3) => Commutative (IdentityT3 f1 f2 f3) Source | |
| (Commutative f1, Commutative f2, Commutative f3, Commutative f4) => Commutative (IdentityT4 f1 f2 f3 f4) Source | |
| (Commutative f1, Commutative f2, Commutative f3, Commutative f4, Commutative f5) => Commutative (IdentityT5 f1 f2 f3 f4 f5) Source |
Utility functions
cmap :: (Applicative f, Commutative c) => (a -> f b) -> c a -> f (c b) Source
Do fmap f then commute, equivalent for .traverse
cfor :: (Applicative f, Commutative c) => c a -> (a -> f b) -> f (c b) Source
General definitions for superclass methods
fmapDefault :: Commutative t => (a -> b) -> t a -> t b Source
This function may be used as a value for fmap in a Functor
instance, provided that commute is defined. (Using
fmapDefault with a Commutative instance will result in infinite recursion.)
foldMapDefault :: (Commutative t, Monoid m) => (a -> m) -> t a -> m Source
Utility functions 2
Level-2
sink2 :: (Commutative m1, Applicative m2, Applicative m3) => m1 (m2 (m3 a)) -> m2 (m3 (m1 a)) Source
sink2 = (commute|$>) . commute
>>>sink2 $ Right (Just [1])Just [Right 1]
float2 :: (Applicative m1, Commutative m2, Commutative m3) => m2 (m3 (m1 a)) -> m1 (m2 (m3 a)) Source
float2 = commute . (commute|$>)
>>>float2 $ Just [Right 1]Right (Just [1])
Level-3
sink3 :: (Commutative m1, Applicative m2, Applicative m3, Applicative m4) => m1 (m2 (m3 (m4 a))) -> m2 (m3 (m4 (m1 a))) Source
sink3 = (sink2|$>) . commute
>>>sink3 $ Right [Just [1]][Just [Right 1]]
float3 :: (Applicative m1, Commutative m2, Commutative m3, Commutative m4) => m2 (m3 (m4 (m1 a))) -> m1 (m2 (m3 (m4 a))) Source
float3 = commute . (float2|$>)
>>>float3 $ [Just [Right 1]]Right [Just [1]]
Level-4
sink4 :: (Commutative m1, Applicative m2, Applicative m3, Applicative m4, Applicative m5) => m1 (m2 (m3 (m4 (m5 a)))) -> m2 (m3 (m4 (m5 (m1 a)))) Source
float4 :: (Applicative m1, Commutative m2, Commutative m3, Commutative m4, Commutative m5) => m2 (m3 (m4 (m5 (m1 a)))) -> m1 (m2 (m3 (m4 (m5 a)))) Source
Level-5
sink5 :: (Commutative m1, Applicative m2, Applicative m3, Applicative m4, Applicative m5, Applicative m6) => m1 (m2 (m3 (m4 (m5 (m6 a))))) -> m2 (m3 (m4 (m5 (m6 (m1 a))))) Source
float5 :: (Applicative m1, Commutative m2, Commutative m3, Commutative m4, Commutative m5, Commutative m6) => m2 (m3 (m4 (m5 (m6 (m1 a))))) -> m1 (m2 (m3 (m4 (m5 (m6 a))))) Source