indextype 0.1.0.0 → 0.2.0.0
raw patch · 4 files changed
+72/−9 lines, 4 filesdep ~basedep ~hspec
Dependency ranges changed: base, hspec
Files
- indextype.cabal +7/−7
- src/Control/IndexT.hs +0/−1
- src/Control/IndexT/Constructor.hs +64/−0
- src/Control/IndexT/Tuple.hs +1/−1
indextype.cabal view
@@ -1,5 +1,5 @@ name: indextype-version: 0.1.0.0+version: 0.2.0.0 synopsis: A series of type families and constraints for "indexable" types. description: This package deals with types that can roughly be "indexed" at compile time by an integer.@@ -7,7 +7,7 @@ A number of type functions allow one to extract these subtypes, i.e. the type of the 2nd element of a given tuple. Furthermore, constraints are defined which allow one to easily constrain types to these index types,- e.g. a constraint that says "@t@ is a 3 tuple". @Control.IndexT@ has more detail.+ e.g. a constraint that says "'t' is a 3 tuple". 'Control.IndexT' has more detail. author: Clinton Mead maintainer: clintonmead@gmail.com category: Control@@ -17,22 +17,22 @@ build-type: Simple cabal-version: >=1.10 tested-with: GHC == 8.0.2-bug-reports:+bug-reports: https://github.com/clintonmead/indextype/issues source-repository head type: git location: https://github.com/clintonmead/indextype.git library- exposed-modules: Control.IndexT, Control.IndexT.Tuple, Control.IndexT.Function- build-depends: base >= 4.7 && < 5+ exposed-modules: Control.IndexT, Control.IndexT.Tuple, Control.IndexT.Function, Control.IndexT.Constructor+ build-depends: base == 4.9.* hs-source-dirs: src default-language: Haskell2010 Test-Suite tests type: exitcode-stdio-1.0 main-is: Tests.hs- other-modules: Control.IndexT, Control.IndexT.Tuple, Control.IndexT.Function- build-depends: base >= 4.7 && < 5, hspec+ other-modules: Control.IndexT, Control.IndexT.Tuple, Control.IndexT.Function, Control.IndexT.Constructor+ build-depends: base == 4.9.*, hspec == 2.4.* hs-source-dirs: test, src default-language: Haskell2010
src/Control/IndexT.hs view
@@ -42,7 +42,6 @@ ) where import GHC.TypeLits (Nat)-import GHC.Exts (Constraint) import Data.Functor.Identity (Identity) {-|
+ src/Control/IndexT/Constructor.hs view
@@ -0,0 +1,64 @@+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE KindSignatures #-}+{-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE UndecidableInstances #-}++{-|+This module provides a way to constrain types to be data constructors, much like+"Control.IndexT.Tuple" and "Control.IndexT.Function".++It also provides type families for accessing the elements of those data constructors,+both the constructors themselves and the parameters to them.++Note I haven't yet wrote code to generate many instances for these, so currently only+constructors with up to two parameters is supported. Just nag me if your application+needs more.+-}+module Control.IndexT.Constructor (+ IndexC,+ -- $getConstructorDocs+ GetConstructor1,+ GetConstructor2,+ IsData+)+where++import GHC.TypeLits (Nat)+import GHC.Exts (Constraint)++{-|+> IndexC i n (f a_0 a_1 .. a_(n-1))++the ith (zero based) parameter of the constructor with n parameters, i.e. @a_i@+-}+type family IndexC (n :: Nat) (i :: Nat) a++type instance IndexC 1 0 (_ a) = a+type instance IndexC 2 0 (_ a _) = a+type instance IndexC 2 1 (_ _ a) = a++{- $getConstructorDocs+These functions actually get the constructor, Unfortunately these are separate named functions instead+of being indexed by @n@ because they have different kinds, i.e. 'GetConstructor1' is @* -> *@+whereas 'GetConstructor2' is @* -> * -> *@. If there's a better way of doing this let me know.+-}+type family GetConstructor1 a where+ GetConstructor1 (f _) = f++type family GetConstructor2 a where+ GetConstructor2 (f _ _) = f++type Data1 a = (GetConstructor1 a) (IndexC 1 0 a)+type IsData1 a = (a ~ Data1 a)++type Data2 a = (GetConstructor2 a) (IndexC 2 0 a) (IndexC 2 1 a)+type IsData2 a = (a ~ Data2 a)++{-|+Much like 'Control.IndexT.Tuple.IsTuple' and 'Control.IndexT.Function.IsFunction', @IsData m t@ asserts that+@t@ is a data constructor with @n@ variables.+-}+type family IsData (n :: Nat) a :: Constraint+type instance IsData 1 a = IsData1 a+type instance IsData 2 a = IsData2 a
src/Control/IndexT/Tuple.hs view
@@ -80,7 +80,7 @@ So @HomoTupleConstraint 3 t@ basically says @t ~ (u,u,u)@ for some @u@, -("Homo" is short for "Homogeneous". Like milk.)+(\"Homo\" is short for \"Homogeneous\". As in, all the same. Or like milk.) -} type family HomoTupleConstraint (n :: Nat) a :: Constraint type instance HomoTupleConstraint 0 a = (TupleConstraint 0 a)