|
1 |
| -{-# LANGUAGE ExplicitForAll, StandaloneDeriving, DuplicateRecordFields, ScopedTypeVariables, InstanceSigs, KindSignatures, GADTs, FlexibleContexts, RankNTypes, TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses, AllowAmbiguousTypes, TypeOperators |
2 |
| -,LiberalTypeSynonyms, ImpredicativeTypes, UndecidableInstances, FunctionalDependencies, ConstraintKinds, TypeFamilies, DataKinds #-} |
| 1 | +{-# LANGUAGE AllowAmbiguousTypes #-} |
| 2 | +{-# LANGUAGE ConstraintKinds #-} |
| 3 | +{-# LANGUAGE DataKinds #-} |
| 4 | +{-# LANGUAGE DuplicateRecordFields #-} |
| 5 | +{-# LANGUAGE ExplicitForAll #-} |
| 6 | +{-# LANGUAGE FlexibleContexts #-} |
| 7 | +{-# LANGUAGE FlexibleInstances #-} |
| 8 | +{-# LANGUAGE GADTs #-} |
| 9 | +{-# LANGUAGE ImpredicativeTypes #-} |
| 10 | +{-# LANGUAGE InstanceSigs #-} |
| 11 | +{-# LANGUAGE KindSignatures #-} |
| 12 | +{-# LANGUAGE LiberalTypeSynonyms #-} |
| 13 | +{-# LANGUAGE MultiParamTypeClasses #-} |
| 14 | +{-# LANGUAGE RankNTypes #-} |
| 15 | +{-# LANGUAGE ScopedTypeVariables #-} |
| 16 | +{-# LANGUAGE TypeFamilies #-} |
| 17 | +{-# LANGUAGE TypeOperators #-} |
| 18 | +{-# LANGUAGE TypeSynonymInstances #-} |
| 19 | +{-# LANGUAGE UndecidableInstances #-} |
3 | 20 |
|
4 | 21 | module Language.Common where
|
5 |
| -import Data.Map.Strict as Map hiding (foldl) |
6 |
| -import Data.Foldable as Foldable (foldl, toList) |
7 |
| -import Data.Kind |
8 |
| -import Data.Typeable |
9 |
| -import Control.DeepSeq |
10 |
| -import Control.Arrow (left) |
11 |
| -import Data.Maybe |
12 |
| -import Data.Set as Set (Set, empty, member, insert, singleton) |
13 |
| -import Data.Char |
| 22 | + |
| 23 | +import Control.Arrow (left) |
| 24 | +import Data.Char |
| 25 | +import Data.Foldable as Foldable (foldl, toList) |
| 26 | +import Data.Kind |
| 27 | +import Data.Map.Strict as Map hiding (foldl) |
| 28 | +import Data.Maybe |
| 29 | +import Data.Set as Set (Set, empty, insert, member, singleton) |
| 30 | +import Data.Typeable |
14 | 31 |
|
15 | 32 | split' :: [(a, Either b1 b2)] -> ([(a, b1)], [(a, b2)])
|
16 | 33 | split' [] = ([],[])
|
@@ -101,14 +118,21 @@ member' k m = elem' k (Map.keys m)
|
101 | 118 | mergeMaps :: Ord k => [Map k v] -> Map k v
|
102 | 119 | mergeMaps = foldl Map.union Map.empty
|
103 | 120 |
|
| 121 | +-- | Allows to set a constraint for multiple type variables at the same time. |
| 122 | +-- For example you could use `TyMap Show '[a, b, c]` instead of |
| 123 | +-- `(Show a, Show b, Show c)` |
| 124 | +-- The drawback of using this is that the compiler will treat this as a unique |
| 125 | +-- constraint, so it won't be able to detect specific unused constraints |
104 | 126 | type family TyMap (f :: * -> Constraint) (xs :: [*]) :: Constraint
|
105 | 127 | type instance TyMap f '[] = ()
|
106 | 128 | type instance TyMap f (t ': ts) = (f t, TyMap f ts)
|
107 | 129 |
|
108 |
| -type family ShowOrdN (xs :: [*]) :: Constraint |
109 |
| -type instance ShowOrdN '[] = () |
110 |
| -type instance ShowOrdN (t ': ts) = (Show t, Ord t, NFData t, ShowOrdN ts) |
111 |
| - |
112 |
| -type family ShowOrdTypeableN (xs :: [*]) :: Constraint |
113 |
| -type instance ShowOrdTypeableN '[] = () |
114 |
| -type instance ShowOrdTypeableN (t ': ts) = (Show t, Ord t, Typeable t, NFData t, ShowOrdTypeableN ts) |
| 130 | +-- | Allows to set multiple contraints for multiple type variables at the same |
| 131 | +-- time. |
| 132 | +-- For example you could use `MultiTyMap '[Show, Ord] '[a, b, c]` insted of |
| 133 | +-- `(Show a, Ord a, Show b, Ord b, Show c, Ord c)` |
| 134 | +-- The drawback of using this is that the compiler will treat this as a unique |
| 135 | +-- constraint, so it won't be able to detect specific unused constraints |
| 136 | +type family MultiTyMap (fs :: [* -> Constraint]) (xs :: [*]) :: Constraint |
| 137 | +type instance MultiTyMap '[] _ = () |
| 138 | +type instance MultiTyMap (f : fs) xs = (TyMap f xs, MultiTyMap fs xs) |
0 commit comments