1 {-# LANGUAGE TypeFamilyDependencies #-}
2 {-# LANGUAGE UndecidableInstances #-}
3 module Symantic.Base.Permutable where
5 import Data.Function ((.))
6 import Data.Maybe (Maybe(..), fromJust)
8 import Symantic.Base.Composable
9 import Symantic.Base.Algebrable
11 -- * Class 'Permutable'
12 class Permutable repr where
13 -- Use @TypeFamilyDependencies@ to help type-inference infer @(repr)@.
14 type Permutation (repr:: * -> * -> *) = (r :: * -> * -> *) | r -> repr
15 type Permutation repr = Permutation (UnTrans repr)
16 permutable :: Permutation repr (a->k) k -> repr (a->k) k
17 perm :: repr (a->k) k -> Permutation repr (a->k) k
18 noPerm :: Permutation repr k k
19 permWithDefault :: a -> repr (a->k) k -> Permutation repr (a->k) k
21 Eitherable repr => Dimapable repr => Permutable repr =>
22 repr (a->k) k -> Permutation repr (Maybe a -> k) k
23 optionalPerm = permWithDefault Nothing . dimap Just fromJust
27 Tupable (Permutation repr) =>
29 Permutation repr (b->k) k ->
30 Permutation repr ((a,b)->k) k
31 x <&> y = perm x <:> y
37 Tupable (Permutation repr) =>
39 Permutation repr (b->k) k ->
40 Permutation repr ((Maybe a,b)->k) k
41 x <?&> y = optionalPerm x <:> y
48 Tupable (Permutation repr) =>
50 Permutation repr (b->k) k ->
51 Permutation repr (([a],b)->k) k
52 x <*&> y = permWithDefault [] (many1 x) <:> y
59 Tupable (Permutation repr) =>
61 Permutation repr (b->k) k ->
62 Permutation repr (([a],b)->k) k
63 x <+&> y = perm (many1 x) <:> y