1 {-# LANGUAGE TypeFamilyDependencies #-}
2 {-# LANGUAGE UndecidableInstances #-}
3 module Symantic.Dityped.Permutable where
5 import Data.Function ((.))
6 import Data.Maybe (Maybe(..), fromJust)
8 import Symantic.Dityped.Transformable
9 import Symantic.Dityped.Composable
10 import Symantic.Dityped.Algebrable
12 -- * Class 'Permutable'
13 class Permutable repr where
14 -- Use @TypeFamilyDependencies@ to help type-inference infer @(repr)@.
15 type Permutation (repr:: * -> * -> *) = (r :: * -> * -> *) | r -> repr
16 type Permutation repr = Permutation (Unlifted repr)
17 permutable :: Permutation repr (a->k) k -> repr (a->k) k
18 perm :: repr (a->k) k -> Permutation repr (a->k) k
19 noPerm :: Permutation repr k k
20 permWithDefault :: a -> repr (a->k) k -> Permutation repr (a->k) k
22 Eitherable repr => Dimapable repr => Permutable repr =>
23 repr (a->k) k -> Permutation repr (Maybe a -> k) k
24 optionalPerm = permWithDefault Nothing . dimap Just fromJust
28 Tupable (Permutation repr) =>
30 Permutation repr (b->k) k ->
31 Permutation repr ((a,b)->k) k
32 x <&> y = perm x <:> y
38 Tupable (Permutation repr) =>
40 Permutation repr (b->k) k ->
41 Permutation repr ((Maybe a,b)->k) k
42 x <?&> y = optionalPerm x <:> y
49 Tupable (Permutation repr) =>
51 Permutation repr (b->k) k ->
52 Permutation repr (([a],b)->k) k
53 x <*&> y = permWithDefault [] (many1 x) <:> y
60 Tupable (Permutation repr) =>
62 Permutation repr (b->k) k ->
63 Permutation repr (([a],b)->k) k
64 x <+&> y = perm (many1 x) <:> y