kinds 0.0.1.1 → 0.0.1.2
raw patch · 2 files changed
+42/−42 lines, 2 filesPVP ok
version bump matches the API change (PVP)
API changes (from Hackage documentation)
Files
- kinds.cabal +1/−1
- src/Data/Kind.hs +41/−41
kinds.cabal view
@@ -1,5 +1,5 @@ Name: kinds-Version: 0.0.1.1+Version: 0.0.1.2 Cabal-Version: >= 1.2.3 Build-Type: Simple License: BSD3
src/Data/Kind.hs view
@@ -4,73 +4,73 @@ Imagine, we had a language extension for declaring subkinds of kind @*@ where a subkind declaration would be written as follows: - @- subkind /K/ = /C_1/ => /t_1/ | ... | /C_n/ => /t_n/- @+@+subkind /K/ = /C_1/ => /t_1/ | ... | /C_n/ => /t_n/+@ Thereby, @/K/@ would be a kind identifier, the @/t_i/@ would be types and the @/C_i/@ would be contexts. This subkind declaration would introduce a subkind @/K/@ that covers all types that match one of the @/t_i/@ and fulfill the corresponding context. For example, the declaration - @- subkind Map = (Ord key) => Map key val | IntMap val- @+@+subkind Map = (Ord key) => Map key val | IntMap val+@ would declare the subkind @Map@ of all types whose values are maps. Note that the subkind @Map@ would be different from the type @Map@. We will now see how a subkind declaration - @- subkind /K/ = /C_1/ => /t_1/ | ... | /C_n/ => /t_n/- @+@+subkind /K/ = /C_1/ => /t_1/ | ... | /C_n/ => /t_n/+@ can be emulated using this module. First, we declare a type @Kind/K/@ with a nullary data constructor of the same name for representing the subkind. Then we add the following instance declaration: - @- instance Kind Kind/K/ where-  - data All Kind/K/ item = All/K/ (forall /A_1/. /C_1/ => item /t_1/)- ...- (forall /A_n/. /C_n/ => item /t_n/)-  - closed item = All/K/ item ... item- @+@+instance Kind Kind/K/ where+ + data All Kind/K/ item = All/K/ (forall /A_1/. /C_1/ => item /t_1/)+ ...+ (forall /A_n/. /C_n/ => item /t_n/)+ + closed item = All/K/ item ... item+@ Thereby, each @/A_i/@ stands for a whitespace-separated sequence of the free variables of @/t_i/@. Finally, we add the following instance declaration for every @/i/@ between @1@ and @/n/@: - @- instance /C_i/ => Inhabitant Kind/K/ /t_i/ where-  - specialize (All/K/ _ ... _ item _ ... _) = item- @+@+instance /C_i/ => Inhabitant Kind/K/ /t_i/ where+ + specialize (All/K/ _ ... _ item _ ... _) = item+@ Thereby, the number of wildcard patterns before and after @item@ is @/i/ - 1@ and @/n/ - /i/@, respectively. The above subkind declaration for @Map@ can be emulated with the following code: - @- data KindMap = KindMap-  - instance Kind KindMap where-  - data All KindMap item = AllMap (forall key val. (Ord key) => item (Map key val))- (forall val. item (IntMap val))-  - closed item = AllMap item item-  - instance (Ord key) => Inhabitant KindMap (Map key val) where-  - specialize (AllMap item _) = item-  - instance Inhabitant KindMap (IntMap val) where-  - specialize (AllMap _ item) = item- @+@+data KindMap = KindMap+ +instance Kind KindMap where+ + data All KindMap item = AllMap (forall key val. (Ord key) => item (Map key val))+ (forall val. item (IntMap val))+ + closed item = AllMap item item+ +instance (Ord key) => Inhabitant KindMap (Map key val) where+ + specialize (AllMap item _) = item+ +instance Inhabitant KindMap (IntMap val) where+ + specialize (AllMap _ item) = item+@ -} module Data.Kind (