packages feed

eliminators 0.4.1 → 0.5

raw patch · 14 files changed

+209/−160 lines, 14 filesdep ~basedep ~singleton-natsdep ~singletonsPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base, singleton-nats, singletons, template-haskell, th-desugar

API changes (from Hackage documentation)

- Data.Eliminator: elimBool :: forall (p_alnV :: (~>) Bool Type) (s_alnW :: Bool). Sing s_alnW -> (@@) p_alnV False -> (@@) p_alnV True -> (@@) p_alnV s_alnW
+ Data.Eliminator: elimBool :: forall (p_aw4L :: (~>) Bool Type) (s_aw4M :: Bool). Sing s_aw4M -> Apply p_aw4L 'False -> Apply p_aw4L 'True -> Apply p_aw4L s_aw4M
- Data.Eliminator: elimEither :: forall (a_aiOT :: Type) (b_aiOU :: Type) (p_alo7 :: (~>) (Either a_aiOT b_aiOU) Type) (s_alo8 :: Either a_aiOT b_aiOU). Sing s_alo8 -> (forall (f0_alo9 :: a_aiOT). Sing f0_alo9 -> (@@) p_alo7 (Left f0_alo9)) -> (forall (f0_aloa :: b_aiOU). Sing f0_aloa -> (@@) p_alo7 (Right f0_aloa)) -> (@@) p_alo7 s_alo8
+ Data.Eliminator: elimEither :: forall (a_aw4R :: Type) (b_aw4S :: Type) (p_aw55 :: (~>) (Either a_aw4R b_aw4S) Type) (s_aw56 :: Either a_aw4R b_aw4S). Sing s_aw56 -> (forall (f0_aw57 :: a_aw4R). Sing f0_aw57 -> Apply p_aw55 ( 'Left f0_aw57)) -> (forall (f0_aw58 :: b_aw4S). Sing f0_aw58 -> Apply p_aw55 ( 'Right f0_aw58)) -> Apply p_aw55 s_aw56
- Data.Eliminator: elimList :: forall (a_11 :: Type) (p_alAe :: (~>) ([] a_11) Type) (s_alAf :: [] a_11). Sing s_alAf -> (@@) p_alAe [] -> (forall (f0_alAg :: a_11). Sing f0_alAg -> forall (f1_alAh :: [a_11]). Sing f1_alAh -> (@@) p_alAe f1_alAh -> (@@) p_alAe ((:) f0_alAg f1_alAh)) -> (@@) p_alAe s_alAf
+ Data.Eliminator: elimList :: forall (a_11 :: Type) (p_awz4 :: (~>) ([] a_11) Type) (s_awz5 :: [] a_11). Sing s_awz5 -> Apply p_awz4 '[] -> (forall (f0_awz6 :: a_11). Sing f0_awz6 -> forall (f1_awz7 :: [a_11]). Sing f1_awz7 -> Apply p_awz4 f1_awz7 -> Apply p_awz4 ( '(:) f0_awz6 f1_awz7)) -> Apply p_awz4 s_awz5
- Data.Eliminator: elimMaybe :: forall (a_11 :: Type) (p_alol :: (~>) (Maybe a_11) Type) (s_alom :: Maybe a_11). Sing s_alom -> (@@) p_alol Nothing -> (forall (f0_alon :: a_11). Sing f0_alon -> (@@) p_alol (Just f0_alon)) -> (@@) p_alol s_alom
+ Data.Eliminator: elimMaybe :: forall (a_11 :: Type) (p_aw5j :: (~>) (Maybe a_11) Type) (s_aw5k :: Maybe a_11). Sing s_aw5k -> Apply p_aw5j 'Nothing -> (forall (f0_aw5l :: a_11). Sing f0_aw5l -> Apply p_aw5j ( 'Just f0_aw5l)) -> Apply p_aw5j s_aw5k
- Data.Eliminator: elimNat :: forall (p_alow :: (~>) Nat Type) (s_alox :: Nat). Sing s_alox -> (@@) p_alow Z -> (forall (f0_aloy :: Nat). Sing f0_aloy -> (@@) p_alow f0_aloy -> (@@) p_alow (S f0_aloy)) -> (@@) p_alow s_alox
+ Data.Eliminator: elimNat :: forall (p_aw5u :: (~>) Nat Type) (s_aw5v :: Nat). Sing s_aw5v -> Apply p_aw5u 'Z -> (forall (f0_aw5w :: Nat). Sing f0_aw5w -> Apply p_aw5u f0_aw5w -> Apply p_aw5u ( 'S f0_aw5w)) -> Apply p_aw5u s_aw5v
- Data.Eliminator: elimNonEmpty :: forall (a_ac3J :: Type) (p_aloG :: (~>) (NonEmpty a_ac3J) Type) (s_aloH :: NonEmpty a_ac3J). Sing s_aloH -> (forall (f0_aloI :: a_ac3J). Sing f0_aloI -> forall (f1_aloJ :: [a_ac3J]). Sing f1_aloJ -> (@@) p_aloG ((:|) f0_aloI f1_aloJ)) -> (@@) p_aloG s_aloH
+ Data.Eliminator: elimNonEmpty :: forall (a_alXE :: Type) (p_aw5E :: (~>) (NonEmpty a_alXE) Type) (s_aw5F :: NonEmpty a_alXE). Sing s_aw5F -> (forall (f0_aw5G :: a_alXE). Sing f0_aw5G -> forall (f1_aw5H :: [a_alXE]). Sing f1_aw5H -> Apply p_aw5E ( '(:|) f0_aw5G f1_aw5H)) -> Apply p_aw5E s_aw5F
- Data.Eliminator: elimOrdering :: forall (p_aloS :: (~>) Ordering Type) (s_aloT :: Ordering). Sing s_aloT -> (@@) p_aloS LT -> (@@) p_aloS EQ -> (@@) p_aloS GT -> (@@) p_aloS s_aloT
+ Data.Eliminator: elimOrdering :: forall (p_aw5Q :: (~>) Ordering Type) (s_aw5R :: Ordering). Sing s_aw5R -> Apply p_aw5Q 'LT -> Apply p_aw5Q 'EQ -> Apply p_aw5Q 'GT -> Apply p_aw5Q s_aw5R
- Data.Eliminator: elimTuple0 :: forall (p_alEf :: (~>) () Type) (s_alEg :: ()). Sing s_alEg -> (@@) p_alEf () -> (@@) p_alEf s_alEg
+ Data.Eliminator: elimTuple0 :: forall (p_awDO :: (~>) () Type) (s_awDP :: ()). Sing s_awDP -> Apply p_awDO '() -> Apply p_awDO s_awDP
- Data.Eliminator: elimTuple2 :: forall (a_11 :: Type) (b_12 :: Type) (p_alEk :: (~>) ((,) a_11 b_12) Type) (s_alEl :: (,) a_11 b_12). Sing s_alEl -> (forall (f0_alEm :: a_11). Sing f0_alEm -> forall (f1_alEn :: b_12). Sing f1_alEn -> (@@) p_alEk ((,) f0_alEm f1_alEn)) -> (@@) p_alEk s_alEl
+ Data.Eliminator: elimTuple2 :: forall (a_11 :: Type) (b_12 :: Type) (p_awDT :: (~>) ((,) a_11 b_12) Type) (s_awDU :: (,) a_11 b_12). Sing s_awDU -> (forall (f0_awDV :: a_11). Sing f0_awDV -> forall (f1_awDW :: b_12). Sing f1_awDW -> Apply p_awDT ( '(,) f0_awDV f1_awDW)) -> Apply p_awDT s_awDU
- Data.Eliminator: elimTuple3 :: forall (a_11 :: Type) (b_12 :: Type) (c_13 :: Type) (p_alEw :: (~>) ((,,) a_11 b_12 c_13) Type) (s_alEx :: (,,) a_11 b_12 c_13). Sing s_alEx -> (forall (f0_alEy :: a_11). Sing f0_alEy -> forall (f1_alEz :: b_12). Sing f1_alEz -> forall (f2_alEA :: c_13). Sing f2_alEA -> (@@) p_alEw ((,,) f0_alEy f1_alEz f2_alEA)) -> (@@) p_alEw s_alEx
+ Data.Eliminator: elimTuple3 :: forall (a_11 :: Type) (b_12 :: Type) (c_13 :: Type) (p_awE5 :: (~>) ((,,) a_11 b_12 c_13) Type) (s_awE6 :: (,,) a_11 b_12 c_13). Sing s_awE6 -> (forall (f0_awE7 :: a_11). Sing f0_awE7 -> forall (f1_awE8 :: b_12). Sing f1_awE8 -> forall (f2_awE9 :: c_13). Sing f2_awE9 -> Apply p_awE5 ( '(,,) f0_awE7 f1_awE8 f2_awE9)) -> Apply p_awE5 s_awE6
- Data.Eliminator: elimTuple4 :: forall (a_11 :: Type) (b_12 :: Type) (c_13 :: Type) (d_14 :: Type) (p_alEM :: (~>) ((,,,) a_11 b_12 c_13 d_14) Type) (s_alEN :: (,,,) a_11 b_12 c_13 d_14). Sing s_alEN -> (forall (f0_alEO :: a_11). Sing f0_alEO -> forall (f1_alEP :: b_12). Sing f1_alEP -> forall (f2_alEQ :: c_13). Sing f2_alEQ -> forall (f3_alER :: d_14). Sing f3_alER -> (@@) p_alEM ((,,,) f0_alEO f1_alEP f2_alEQ f3_alER)) -> (@@) p_alEM s_alEN
+ Data.Eliminator: elimTuple4 :: forall (a_11 :: Type) (b_12 :: Type) (c_13 :: Type) (d_14 :: Type) (p_awEl :: (~>) ((,,,) a_11 b_12 c_13 d_14) Type) (s_awEm :: (,,,) a_11 b_12 c_13 d_14). Sing s_awEm -> (forall (f0_awEn :: a_11). Sing f0_awEn -> forall (f1_awEo :: b_12). Sing f1_awEo -> forall (f2_awEp :: c_13). Sing f2_awEp -> forall (f3_awEq :: d_14). Sing f3_awEq -> Apply p_awEl ( '(,,,) f0_awEn f1_awEo f2_awEp f3_awEq)) -> Apply p_awEl s_awEm
- Data.Eliminator: elimTuple5 :: forall (a_11 :: Type) (b_12 :: Type) (c_13 :: Type) (d_14 :: Type) (e_15 :: Type) (p_alF6 :: (~>) ((,,,,) a_11 b_12 c_13 d_14 e_15) Type) (s_alF7 :: (,,,,) a_11 b_12 c_13 d_14 e_15). Sing s_alF7 -> (forall (f0_alF8 :: a_11). Sing f0_alF8 -> forall (f1_alF9 :: b_12). Sing f1_alF9 -> forall (f2_alFa :: c_13). Sing f2_alFa -> forall (f3_alFb :: d_14). Sing f3_alFb -> forall (f4_alFc :: e_15). Sing f4_alFc -> (@@) p_alF6 ((,,,,) f0_alF8 f1_alF9 f2_alFa f3_alFb f4_alFc)) -> (@@) p_alF6 s_alF7
+ Data.Eliminator: elimTuple5 :: forall (a_11 :: Type) (b_12 :: Type) (c_13 :: Type) (d_14 :: Type) (e_15 :: Type) (p_awEF :: (~>) ((,,,,) a_11 b_12 c_13 d_14 e_15) Type) (s_awEG :: (,,,,) a_11 b_12 c_13 d_14 e_15). Sing s_awEG -> (forall (f0_awEH :: a_11). Sing f0_awEH -> forall (f1_awEI :: b_12). Sing f1_awEI -> forall (f2_awEJ :: c_13). Sing f2_awEJ -> forall (f3_awEK :: d_14). Sing f3_awEK -> forall (f4_awEL :: e_15). Sing f4_awEL -> Apply p_awEF ( '(,,,,) f0_awEH f1_awEI f2_awEJ f3_awEK f4_awEL)) -> Apply p_awEF s_awEG
- Data.Eliminator: elimTuple6 :: forall (a_11 :: Type) (b_12 :: Type) (c_13 :: Type) (d_14 :: Type) (e_15 :: Type) (f_16 :: Type) (p_alFu :: (~>) ((,,,,,) a_11 b_12 c_13 d_14 e_15 f_16) Type) (s_alFv :: (,,,,,) a_11 b_12 c_13 d_14 e_15 f_16). Sing s_alFv -> (forall (f0_alFw :: a_11). Sing f0_alFw -> forall (f1_alFx :: b_12). Sing f1_alFx -> forall (f2_alFy :: c_13). Sing f2_alFy -> forall (f3_alFz :: d_14). Sing f3_alFz -> forall (f4_alFA :: e_15). Sing f4_alFA -> forall (f5_alFB :: f_16). Sing f5_alFB -> (@@) p_alFu ((,,,,,) f0_alFw f1_alFx f2_alFy f3_alFz f4_alFA f5_alFB)) -> (@@) p_alFu s_alFv
+ Data.Eliminator: elimTuple6 :: forall (a_11 :: Type) (b_12 :: Type) (c_13 :: Type) (d_14 :: Type) (e_15 :: Type) (f_16 :: Type) (p_awF3 :: (~>) ((,,,,,) a_11 b_12 c_13 d_14 e_15 f_16) Type) (s_awF4 :: (,,,,,) a_11 b_12 c_13 d_14 e_15 f_16). Sing s_awF4 -> (forall (f0_awF5 :: a_11). Sing f0_awF5 -> forall (f1_awF6 :: b_12). Sing f1_awF6 -> forall (f2_awF7 :: c_13). Sing f2_awF7 -> forall (f3_awF8 :: d_14). Sing f3_awF8 -> forall (f4_awF9 :: e_15). Sing f4_awF9 -> forall (f5_awFa :: f_16). Sing f5_awFa -> Apply p_awF3 ( '(,,,,,) f0_awF5 f1_awF6 f2_awF7 f3_awF8 f4_awF9 f5_awFa)) -> Apply p_awF3 s_awF4
- Data.Eliminator: elimTuple7 :: forall (a_11 :: Type) (b_12 :: Type) (c_13 :: Type) (d_14 :: Type) (e_15 :: Type) (f_16 :: Type) (g_17 :: Type) (p_alFW :: (~>) ((,,,,,,) a_11 b_12 c_13 d_14 e_15 f_16 g_17) Type) (s_alFX :: (,,,,,,) a_11 b_12 c_13 d_14 e_15 f_16 g_17). Sing s_alFX -> (forall (f0_alFY :: a_11). Sing f0_alFY -> forall (f1_alFZ :: b_12). Sing f1_alFZ -> forall (f2_alG0 :: c_13). Sing f2_alG0 -> forall (f3_alG1 :: d_14). Sing f3_alG1 -> forall (f4_alG2 :: e_15). Sing f4_alG2 -> forall (f5_alG3 :: f_16). Sing f5_alG3 -> forall (f6_alG4 :: g_17). Sing f6_alG4 -> (@@) p_alFW ((,,,,,,) f0_alFY f1_alFZ f2_alG0 f3_alG1 f4_alG2 f5_alG3 f6_alG4)) -> (@@) p_alFW s_alFX
+ Data.Eliminator: elimTuple7 :: forall (a_11 :: Type) (b_12 :: Type) (c_13 :: Type) (d_14 :: Type) (e_15 :: Type) (f_16 :: Type) (g_17 :: Type) (p_awFv :: (~>) ((,,,,,,) a_11 b_12 c_13 d_14 e_15 f_16 g_17) Type) (s_awFw :: (,,,,,,) a_11 b_12 c_13 d_14 e_15 f_16 g_17). Sing s_awFw -> (forall (f0_awFx :: a_11). Sing f0_awFx -> forall (f1_awFy :: b_12). Sing f1_awFy -> forall (f2_awFz :: c_13). Sing f2_awFz -> forall (f3_awFA :: d_14). Sing f3_awFA -> forall (f4_awFB :: e_15). Sing f4_awFB -> forall (f5_awFC :: f_16). Sing f5_awFC -> forall (f6_awFD :: g_17). Sing f6_awFD -> Apply p_awFv ( '(,,,,,,) f0_awFx f1_awFy f2_awFz f3_awFA f4_awFB f5_awFC f6_awFD)) -> Apply p_awFv s_awFw
- Data.Eliminator: elimVoid :: forall (p_alp3 :: (~>) Void Type) (s_alp4 :: Void). Sing s_alp4 -> (@@) p_alp3 s_alp4
+ Data.Eliminator: elimVoid :: forall (p_aw61 :: (~>) Void Type) (s_aw62 :: Void). Sing s_aw62 -> Apply p_aw61 s_aw62
- Data.Eliminator.TypeNats: elimNat :: forall (p :: Nat ~> Type) (n :: Nat). Sing n -> p @@ 0 -> (forall (k :: Nat). Sing k -> p @@ k -> p @@ (k + 1)) -> p @@ n
+ Data.Eliminator.TypeNats: elimNat :: forall (p :: Nat ~> Type) (n :: Nat). Sing n -> Apply p 0 -> (forall (k :: Nat). Sing k -> Apply p k -> Apply p (k + 1)) -> Apply p n

Files

CHANGELOG.md view
@@ -1,3 +1,6 @@+## 0.5 [2018.09.18]+* Require `singletons-2.5` and GHC 8.6.+ ### 0.4.1 [2018.02.13] * Add `elimVoid` to `Data.Eliminator`. 
eliminators.cabal view
@@ -1,5 +1,5 @@ name:                eliminators-version:             0.4.1+version:             0.5 synopsis:            Dependently typed elimination functions using singletons description:         This library provides eliminators for inductive data types,                      leveraging the power of the @singletons@ library to allow@@ -16,7 +16,7 @@ build-type:          Simple extra-source-files:  CHANGELOG.md, README.md cabal-version:       >=1.10-tested-with:         GHC == 8.4.1+tested-with:         GHC == 8.6.1  source-repository head   type:                git@@ -26,13 +26,13 @@   exposed-modules:     Data.Eliminator                        Data.Eliminator.TH                        Data.Eliminator.TypeNats-  build-depends:       base             >= 4.11    && < 4.12-                     , extra            >= 1.4.2   && < 1.7-                     , singletons       >= 2.4.1   && < 2.5-                     , singleton-nats   >= 0.4.0.4 && < 0.5-                     , template-haskell >= 2.13    && < 2.14-                     , th-abstraction   >= 0.2.3   && < 0.3-                     , th-desugar       >= 1.8     && < 1.9+  build-depends:       base             >= 4.12  && < 4.13+                     , extra            >= 1.4.2 && < 1.7+                     , singletons       >= 2.5   && < 2.6+                     , singleton-nats   >= 0.4.2 && < 0.5+                     , template-haskell >= 2.14  && < 2.15+                     , th-abstraction   >= 0.2.3 && < 0.3+                     , th-desugar       >= 1.9   && < 1.10   hs-source-dirs:      src   default-language:    Haskell2010   ghc-options:         -Wall -Wno-unticked-promoted-constructors@@ -43,16 +43,17 @@   other-modules:       DecideSpec                        DecideTypes                        EqualitySpec+                       EqualityTypes                        GADTSpec                        ListSpec                        ListTypes                        VecTypes                        VecSpec-  build-depends:       base           >= 4.11    && < 4.12+  build-depends:       base           >= 4.12  && < 4.13                      , eliminators-                     , hspec          >= 2       && < 3-                     , singletons     >= 2.4.1   && < 2.5-                     , singleton-nats >= 0.4.0.4 && < 0.5+                     , hspec          >= 2     && < 3+                     , singletons     >= 2.5   && < 2.6+                     , singleton-nats >= 0.4.2 && < 0.5   build-tool-depends:  hspec-discover:hspec-discover   hs-source-dirs:      tests   default-language:    Haskell2010
src/Data/Eliminator.hs view
@@ -1,15 +1,16 @@ {-# LANGUAGE AllowAmbiguousTypes #-} {-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE DataKinds #-} {-# LANGUAGE EmptyCase #-} {-# LANGUAGE ExistentialQuantification #-} {-# LANGUAGE GADTs #-}+{-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE Trustworthy #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE TypeInType #-} {-# LANGUAGE TypeOperators #-} {-| Module:      Data.Eliminator@@ -55,9 +56,9 @@ {- $eliminators  These eliminators are defined with propositions of kind @\<Datatype\> ~> 'Type'@-(that is, using the '(~>)' kind). These eliminators are designed for+(that is, using the @('~>')@ kind). These eliminators are designed for defunctionalized (i.e., \"partially applied\") types as predicates,-and as a result, the predicates must be applied manually with '(@@)'.+and as a result, the predicates must be applied manually with 'Apply'.  The naming conventions are: 
src/Data/Eliminator/TH.hs view
@@ -46,11 +46,11 @@ @ elimMyList :: forall (a :: 'Type') (p :: MyList a '~>' 'Type') (l :: MyList a).               'Sing' l-           -> p '@@' MyNil+           -> 'Apply' p MyNil            -> (forall (x :: a). 'Sing' x-                -> forall (xs :: MyList a). 'Sing' xs -> p '@@' xs-                -> p '@@' (MyCons x xs))-           -> p '@@' l+                -> forall (xs :: MyList a). 'Sing' xs -> 'Apply' p xs+                -> 'Apply' p (MyCons x xs))+           -> 'Apply' p l elimMyList SMyNil pMyNil _ = pMyNil elimMyList (SMyCons (x' :: 'Sing' x) (xs' :: 'Sing' xs)) pMyNil pMyCons   = pMyCons x' xs' (elimMyList \@a \@p \@xs pMyNil pMyCons)@@ -82,7 +82,7 @@        in a second.    The return type is the predicate type variable applied to the data type-  (@p '@@' (MyCons x xs)@, the above example).+  (@'Apply' p (MyCons x xs)@, the above example).    The type of each constructor argument also follows certain conventions: @@ -96,20 +96,24 @@        explained using the above example. In the @MyCons@ constructor, the second        field (of type @MyCons a@) is a recursive occurrence of @MyCons@, so        that corresponds to the type-       @forall (xs :: MyList a). 'Sing' xs -> p '@@' xs@, where @p '@@' xs@+       @forall (xs :: MyList a). 'Sing' xs -> 'Apply' p xs@, where @'Apply' p xs@        is only present due to the recursion.      3. Finally, the return type will be the predicate type variable applied        to a saturated occurrence of the data constructor-       (@p '@@' (MyCons x xs)@, in the above example).+       (@'Apply' p (MyCons x xs)@, in the above example).  * You'll need to enable lots of GHC extensions in order for the code generated   by 'deriveElim' to typecheck. You'll need at least the following:      * @AllowAmbiguousTypes@ +    * @DataKinds@+     * @GADTs@ +    * @PolyKinds@+     * @RankNTypes@      * @ScopedTypeVariables@@@ -118,8 +122,6 @@      * @TypeApplications@ -    * @TypeInType@- * 'deriveElim' doesn't support every possible data type at the moment.   It is known not to work for the following: @@ -263,9 +265,9 @@ singType :: Name -> Type singType x = ConT ''Sing `AppT` VarT x --- | Construct a type of the form @p '@@' ty@ given @p@ and @ty@.+-- | Construct a type of the form @'Apply' p ty@ given @p@ and @ty@. predType :: Name -> Type -> Type-predType p ty = InfixT (VarT p) ''(@@) ty+predType p ty = ConT ''Apply `AppT` VarT p `AppT` ty  -- | Generate a list of fresh names with a common prefix, and numbered suffixes. newNameList :: String -> Int -> Q [Name]
src/Data/Eliminator/TypeNats.hs view
@@ -1,9 +1,10 @@ {-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE Trustworthy #-} {-# LANGUAGE TypeApplications #-}-{-# LANGUAGE TypeInType #-} {-# LANGUAGE TypeOperators #-} {-| Module:      Data.Eliminator.TypeNats@@ -29,9 +30,9 @@ -- (crudely) pretend that it is using this eliminator. elimNat :: forall (p :: Nat ~> Type) (n :: Nat).            Sing n-        -> p @@ 0-        -> (forall (k :: Nat). Sing k -> p @@ k -> p @@ (k + 1))-        -> p @@ n+        -> Apply p 0+        -> (forall (k :: Nat). Sing k -> Apply p k -> Apply p (k + 1))+        -> Apply p n elimNat snat pZ pS =   case fromSing snat of     0        -> unsafeCoerce pZ
tests/DecideSpec.hs view
@@ -1,9 +1,10 @@+{-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-}+{-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE TypeInType #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-} module DecideSpec where
tests/DecideTypes.hs view
@@ -1,12 +1,13 @@ {-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-}+{-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE TypeInType #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-} module DecideTypes where
tests/EqualitySpec.hs view
@@ -1,13 +1,13 @@ {-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-}+{-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE TypeInType #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-}-{-# OPTIONS_GHC -fno-warn-orphans #-} module EqualitySpec where  import           Data.Kind@@ -15,6 +15,8 @@ import qualified Data.Type.Equality as DTE import           Data.Type.Equality ((:~:)(..), (:~~:)(..)) +import           EqualityTypes+ import           Test.Hspec  main :: IO ()@@ -31,102 +33,57 @@  ----- -data instance Sing (z :: a :~: b) where-  SRefl :: Sing Refl-type (%:~:) = (Sing :: (a :: k) :~: (b :: k) -> Type)--instance SingKind (a :~: b) where-  type Demote (a :~: b) = a :~: b-  fromSing SRefl = Refl-  toSing Refl    = SomeSing SRefl--instance SingI Refl where-  sing = SRefl--(~>:~:) :: forall (k :: Type) (a :: k) (b :: k)-                  (p :: forall (y :: k). a :~: y ~> Type)-                  (r :: a :~: b).-           Sing r-        -> p @@ Refl-        -> p @@ r-(~>:~:) SRefl pRefl = pRefl--data instance Sing (z :: a :~~: b) where-  SHRefl :: Sing HRefl-type (%:~~:) = (Sing :: (a :: j) :~~: (b :: k) -> Type)--instance SingKind (a :~~: b) where-  type Demote (a :~~: b) = a :~~: b-  fromSing SHRefl = HRefl-  toSing HRefl    = SomeSing SHRefl--instance SingI HRefl where-  sing = SHRefl+j :: forall (k :: Type) (a :: k) (b :: k)+            (p :: forall (x :: k) (y :: k). x :~: y ~> Type)+            (r :: a :~: b).+     Sing r+  -> (forall (x :: k). p @@ (Refl :: x :~: x))+  -> p @@ r+j SRefl pRefl = pRefl @a -(~>:~~:) :: forall (j :: Type) (k :: Type) (a :: j) (b :: k)-                   (p :: forall (z :: Type) (y :: z). a :~~: y ~> Type)-                   (r :: a :~~: b).-            Sing r-         -> p @@ HRefl-         -> p @@ r-(~>:~~:) SHRefl pHRefl = pHRefl+hj :: forall (j :: Type) (k :: Type) (a :: j) (b :: k)+             (p :: forall (y :: Type) (z :: Type) (w :: y) (x :: z). w :~~: x ~> Type)+             (r :: a :~~: b).+      Sing r+   -> (forall (y :: Type) (w :: y). p @@ (HRefl :: w :~~: w))+   -> p @@ r+hj SHRefl pHRefl = pHRefl @k @a ------+k :: forall (k :: Type) (a :: k)+            (p :: a :~: a ~> Type)+            (r :: a :~: a).+     Sing r+  -> p @@ Refl+  -> p @@ r+k SRefl pRefl = pRefl -type WhySym (a :: t) (y :: t) (e :: a :~: y) = y :~: a-data WhySymSym (a :: t) :: forall (y :: t). a :~: y ~> Type-type instance Apply (WhySymSym a :: a :~: y ~> Type) x-  = WhySym a y x+hk :: forall (k :: Type) (a :: k)+             (p :: a :~~: a ~> Type)+             (r :: a :~~: a).+      Sing r+   -> p @@ HRefl+   -> p @@ r+hk SHRefl pHRefl = pHRefl  sym :: forall (t :: Type) (a :: t) (b :: t).        a :~: b -> b :~: a sym eq = withSomeSing eq $ \(singEq :: Sing r) ->-           (~>:~:) @t @a @b @(WhySymSym a) @r singEq Refl--type WhyHsym (a :: j) (y :: z) (e :: a :~~: y) = y :~~: a-data WhyHsymSym (a :: j) :: forall (z :: Type) (y :: z). a :~~: y ~> Type-type instance Apply (WhyHsymSym a :: a :~~: y ~> Type) x-  = WhyHsym a y x+           (~>:~:) @t @a @b @(WhySymSym1 a) @r singEq Refl  hsym :: forall (j :: Type) (k :: Type) (a :: j) (b :: k).         a :~~: b -> b :~~: a hsym eq = withSomeSing eq $ \(singEq :: Sing r) ->-            (~>:~~:) @j @k @a @b @(WhyHsymSym a) @r singEq HRefl--type family Symmetry (x :: (a :: k) :~: (b :: k)) :: b :~: a where-  Symmetry Refl = Refl--type WhySymIdempotent (a :: t) (z :: t) (r :: a :~: z)-  = Symmetry (Symmetry r) :~: r-data WhySymIdempotentSym (a :: t) :: forall (z :: t). a :~: z ~> Type-type instance Apply (WhySymIdempotentSym a :: a :~: z ~> Type) r-  = WhySymIdempotent a z r+            (~>:~~:) @j @k @a @b @(WhyHsymSym1 a) @r singEq HRefl  symIdempotent :: forall (t :: Type) (a :: t) (b :: t)                         (e :: a :~: b).                  Sing e -> Symmetry (Symmetry e) :~: e-symIdempotent se = (~>:~:) @t @a @b @(WhySymIdempotentSym a) @e se Refl--type family Hsymmetry (x :: (a :: j) :~~: (b :: k)) :: b :~~: a where-  Hsymmetry HRefl = HRefl--type WhyHsymIdempotent (a :: j) (y :: z) (r :: a :~~: y)-  = Hsymmetry (Hsymmetry r) :~: r-data WhyHsymIdempotentSym (a :: j) :: forall (z :: Type) (y :: z). a :~~: y ~> Type-type instance Apply (WhyHsymIdempotentSym a :: a :~~: y ~> Type) r-  = WhyHsymIdempotent a y r+symIdempotent se = (~>:~:) @t @a @b @(WhySymIdempotentSym1 a) @e se Refl  hsymIdempotent :: forall (j :: Type) (k :: Type) (a :: j) (b :: k)                          (e :: a :~~: b).                   Sing e -> Hsymmetry (Hsymmetry e) :~: e-hsymIdempotent se = (~>:~~:) @j @k @a @b @(WhyHsymIdempotentSym a) @e se Refl--type WhyReplace (from :: t) (p :: t ~> Type)-                (y :: t) (e :: from :~: y) = p @@ y-data WhyReplaceSym (from :: t) (p :: t ~> Type)-  :: forall (y :: t). from :~: y ~> Type-type instance Apply (WhyReplaceSym from p :: from :~: y ~> Type) x-  = WhyReplace from p y x+hsymIdempotent se = (~>:~~:) @j @k @a @b @(WhyHsymIdempotentSym1 a) @e se Refl  replace :: forall (t :: Type) (from :: t) (to :: t) (p :: t ~> Type).            p @@ from@@ -134,16 +91,10 @@         -> p @@ to replace from eq =   withSomeSing eq $ \(singEq :: Sing r) ->-    (~>:~:) @t @from @to @(WhyReplaceSym from p) @r singEq from+    (~>:~:) @t @from @to @(WhyReplaceSym2 from p) @r singEq from +-- Doesn't work due to https://ghc.haskell.org/trac/ghc/ticket/11719 {--type WhyHreplace (from :: j) (p :: forall (z :: Type). z ~> Type)-                 (y :: k) (e :: from :~~: y) = p @@ y-data WhyHreplaceSym (from :: j) (p :: forall (z :: Type). z ~> Type)-  :: forall (k :: Type) (y :: k). from :~~: y ~> Type-type instance Apply (WhyHreplaceSym from p :: from :~~: y ~> Type) x-  = WhyHreplace from p y x- hreplace :: forall (j :: Type) (k :: Type) (from :: j) (to :: k)                    (p :: forall (z :: Type). z ~> Type).             p @@ from@@ -151,27 +102,14 @@          -> p @@ to hreplace from heq =   withSomeSing eq $ \(singEq :: Sing r) ->-    (~>:~~:) @j @k @from @to @(WhyHreplaceSym from p) singEq from+    (@~>:~~:) @j @k @from @to @(WhyHreplaceSym2 from p) singEq from -} -type WhyLeibniz (f :: t ~> Type) (a :: t) (z :: t)-  = f @@ a -> f @@ z-data WhyLeibnizSym (f :: t ~> Type) (a :: t) :: t ~> Type-type instance Apply (WhyLeibnizSym f a) z = WhyLeibniz f a z- leibniz :: forall (t :: Type) (f :: t ~> Type) (a :: t) (b :: t).            a :~: b         -> f @@ a         -> f @@ b-leibniz = replace @t @a @b @(WhyLeibnizSym f a) id--type WhyCong (x :: Type) (y :: Type) (f :: x ~> y)-             (a :: x) (z :: x) (e :: a :~: z)-  = f @@ a :~: f @@ z-data WhyCongSym (x :: Type) (y :: Type) (f :: x ~> y)-                (a :: x) :: forall (z :: x). a :~: z ~> Type-type instance Apply (WhyCongSym x y f a :: a :~: z ~> Type) e-  = WhyCong x y f a z e+leibniz = replace @t @a @b @(WhyLeibnizSym2 f a) id  cong :: forall (x :: Type) (y :: Type) (f :: x ~> y)                (a :: x) (b :: x).@@ -179,22 +117,12 @@      -> f @@ a :~: f @@ b cong eq =   withSomeSing eq $ \(singEq :: Sing r) ->-    (~>:~:) @x @a @b @(WhyCongSym x y f a) @r singEq Refl--type WhyEqIsRefl (a :: k) (z :: k) (e :: a :~: z)-  = e :~~: (Refl :: a :~: a)-data WhyEqIsReflSym (a :: k) :: forall (z :: k). a :~: z ~> Type-type instance Apply (WhyEqIsReflSym a :: a :~: z ~> Type) e = WhyEqIsRefl a z e+    (~>:~:) @x @a @b @(WhyCongSym2 f a) @r singEq Refl  eqIsRefl :: forall (k :: Type) (a :: k) (b :: k) (e :: a :~: b).             Sing e -> e :~~: (Refl :: a :~: a)-eqIsRefl eq = (~>:~:) @k @a @b @(WhyEqIsReflSym a) @e eq HRefl--type WhyHEqIsHRefl (a :: j) (z :: k) (e :: a :~~: z)-  = e :~~: (HRefl :: a :~~: a)-data WhyHEqIsHReflSym (a :: j) :: forall (k :: Type) (z :: k). a :~~: z ~> Type-type instance Apply (WhyHEqIsHReflSym a :: a :~~: z ~> Type) e = WhyHEqIsHRefl a z e+eqIsRefl eq = (~>:~:) @k @a @b @(WhyEqIsReflSym1 a) @e eq HRefl  heqIsHRefl :: forall (j :: Type) (k :: Type) (a :: j) (b :: k) (e :: a :~~: b).               Sing e -> e :~~: (HRefl :: a :~~: a)-heqIsHRefl heq = (~>:~~:) @j @k @a @b @(WhyHEqIsHReflSym a) @e heq HRefl+heqIsHRefl heq = (~>:~~:) @j @k @a @b @(WhyHEqIsHReflSym1 a) @e heq HRefl
+ tests/EqualityTypes.hs view
@@ -0,0 +1,104 @@+{-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE DataKinds #-}+{-# LANGUAGE GADTs #-}+{-# LANGUAGE PolyKinds #-}+{-# LANGUAGE RankNTypes #-}+{-# LANGUAGE ScopedTypeVariables #-}+{-# LANGUAGE TemplateHaskell #-}+{-# LANGUAGE TypeApplications #-}+{-# LANGUAGE TypeFamilies #-}+{-# LANGUAGE TypeOperators #-}+{-# LANGUAGE UndecidableInstances #-}+{-# OPTIONS_GHC -fno-warn-orphans #-}+module EqualityTypes where++import           Data.Kind+import           Data.Singletons.TH+import           Data.Type.Equality ((:~:)(..), (:~~:)(..))++data instance Sing (z :: a :~: b) where+  SRefl :: Sing Refl+type (%:~:) = (Sing :: (a :: k) :~: (b :: k) -> Type)++instance SingKind (a :~: b) where+  type Demote (a :~: b) = a :~: b+  fromSing SRefl = Refl+  toSing Refl    = SomeSing SRefl++instance SingI Refl where+  sing = SRefl++-- | Christine Paulin-Mohring's version of the J rule.+(~>:~:) :: forall (k :: Type) (a :: k) (b :: k)+                  (p :: forall (y :: k). a :~: y ~> Type)+                  (r :: a :~: b).+           Sing r+        -> p @@ Refl+        -> p @@ r+(~>:~:) SRefl pRefl = pRefl++data instance Sing (z :: a :~~: b) where+  SHRefl :: Sing HRefl+type (%:~~:) = (Sing :: (a :: j) :~~: (b :: k) -> Type)++instance SingKind (a :~~: b) where+  type Demote (a :~~: b) = a :~~: b+  fromSing SHRefl = HRefl+  toSing HRefl    = SomeSing SHRefl++instance SingI HRefl where+  sing = SHRefl++-- | Christine Paulin-Mohring's version of the J rule, but heterogeneously kinded.+(~>:~~:) :: forall (j :: Type) (k :: Type) (a :: j) (b :: k)+                   (p :: forall (z :: Type) (y :: z). a :~~: y ~> Type)+                   (r :: a :~~: b).+            Sing r+         -> p @@ HRefl+         -> p @@ r+(~>:~~:) SHRefl pHRefl = pHRefl++-----++$(singletons [d|+  type family WhySym (a :: t) (e :: a :~: (y :: t)) :: Type where+    WhySym a (_ :: a :~: y) = y :~: a++  type family WhyHsym (a :: j) (e :: a :~~: (y :: z)) :: Type where+    WhyHsym a (_ :: a :~~: y)  = y :~~: a++  type family Symmetry (x :: (a :: k) :~: (b :: k)) :: b :~: a where+    Symmetry Refl = Refl++  type family WhySymIdempotent (a :: t) (r :: a :~: (z :: t)) :: Type where+    WhySymIdempotent _ r = Symmetry (Symmetry r) :~: r++  type family Hsymmetry (x :: a :~~: b) :: b :~~: a where+    Hsymmetry HRefl = HRefl++  type family WhyHsymIdempotent (a :: j) (r :: a :~~: (y :: z)) :: Type where+    WhyHsymIdempotent _ r = Hsymmetry (Hsymmetry r) :~: r++  type family WhyReplace (from :: t) (p :: t ~> Type)+                         (e :: from :~: (y :: t)) :: Type where+    WhyReplace from p (_ :: from :~: y) = p @@ y++  -- Doesn't work due to https://ghc.haskell.org/trac/ghc/ticket/11719+  {-+  type family WhyHreplace (from :: j) (p :: forall (z :: Type). z ~> Type)+                          (e :: from :~~: (y :: k)) :: Type where+    WhyHreplace from p (_ :: from :~~: y) = p @@ y+  -}++  type family WhyLeibniz (f :: t ~> Type) (a :: t) (z :: t) :: Type where+    WhyLeibniz f a z = f @@ a -> f @@ z++  type family WhyCong (f :: x ~> y) (a :: x) (e :: a :~: (z :: x)) :: Type where+    WhyCong (f :: x ~> y) (a :: x) (e :: a :~: (z :: x)) = f @@ a :~: f @@ z++  type family WhyEqIsRefl (a :: k) (e :: a :~: (z :: k)) :: Type where+    WhyEqIsRefl a e = e :~~: (Refl :: a :~: a)++  type family WhyHEqIsHRefl (a :: j) (e :: a :~~: (z :: k)) :: Type where+    WhyHEqIsHRefl a e = e :~~: (HRefl :: a :~~: a)+  |])
tests/GADTSpec.hs view
@@ -1,10 +1,11 @@ {-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-}+{-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE TypeInType #-} {-# LANGUAGE TypeOperators #-} module GADTSpec where 
tests/ListSpec.hs view
@@ -1,10 +1,11 @@ {-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-}+{-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE TypeInType #-} {-# LANGUAGE TypeOperators #-} module ListSpec where @@ -32,7 +33,7 @@                       SingI l                    => Length l :~: Length (Map f l) mapPreservesLength-  = elimList @x @(WhyMapPreservesLengthSym1 f) @l (sing @_ @l) base step+  = elimList @x @(WhyMapPreservesLengthSym1 f) @l (sing @l) base step   where     base :: WhyMapPreservesLength f '[]     base = Refl@@ -48,7 +49,7 @@                     SingI l                  => Map f (Map g l) :~: Map (f .@#@$$$ g) l mapFusion-  = elimList @x @(WhyMapFusionSym2 f g) @l (sing @_ @l) base step+  = elimList @x @(WhyMapFusionSym2 f g) @l (sing @l) base step   where     base :: WhyMapFusion f g '[]     base = Refl
tests/ListTypes.hs view
@@ -1,7 +1,8 @@+{-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-}+{-# LANGUAGE PolyKinds #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE TypeInType #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-} module ListTypes where
tests/VecSpec.hs view
@@ -1,7 +1,9 @@+{-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-}+{-# LANGUAGE NoStarIsType #-}+{-# LANGUAGE PolyKinds #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeApplications #-}-{-# LANGUAGE TypeInType #-} {-# LANGUAGE TypeOperators #-} module VecSpec where @@ -77,7 +79,7 @@ mapVec :: forall (a :: Type) (b :: Type) (n :: Nat).           SingI n        => (a -> b) -> Vec a n -> Vec b n-mapVec f = elimNat @(WhyMapVecSym2 a b) @n (sing @_ @n) base step+mapVec f = elimNat @(WhyMapVecSym2 a b) @n (sing @n) base step   where     base :: WhyMapVec a b Z     base _ = VNil@@ -88,7 +90,7 @@ zipWithVec :: forall (a :: Type) (b :: Type) (c :: Type) (n :: Nat).               SingI n            => (a -> b -> c) -> Vec a n -> Vec b n -> Vec c n-zipWithVec f = elimNat @(WhyZipWithVecSym3 a b c) @n (sing @_ @n) base step+zipWithVec f = elimNat @(WhyZipWithVecSym3 a b c) @n (sing @n) base step   where     base :: WhyZipWithVec a b c Z     base _ _ = VNil@@ -103,7 +105,7 @@ appendVec :: forall (e :: Type) (n :: Nat) (m :: Nat).              SingI n           => Vec e n -> Vec e m -> Vec e (n + m)-appendVec = elimNat @(WhyAppendVecSym2 e m) @n (sing @_ @n) base step+appendVec = elimNat @(WhyAppendVecSym2 e m) @n (sing @n) base step   where     base :: WhyAppendVec e m Z     base _ = id@@ -117,10 +119,10 @@ transposeVec :: forall (e :: Type) (n :: Nat) (m :: Nat).                 (SingI n, SingI m)              => Vec (Vec e m) n -> Vec (Vec e n) m-transposeVec = elimNat @(WhyTransposeVecSym2 e m) @n (sing @_ @n) base step+transposeVec = elimNat @(WhyTransposeVecSym2 e m) @n (sing @n) base step   where     base :: WhyTransposeVec e m Z-    base _ = replicateVec (sing @_ @m) VNil+    base _ = replicateVec (sing @m) VNil      step :: forall (k :: Nat).             Sing k
tests/VecTypes.hs view
@@ -1,12 +1,14 @@ {-# LANGUAGE AllowAmbiguousTypes #-}+{-# LANGUAGE DataKinds #-} {-# LANGUAGE GADTs #-}+{-# LANGUAGE NoStarIsType #-}+{-# LANGUAGE PolyKinds #-} {-# LANGUAGE RankNTypes #-} {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE StandaloneDeriving #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE TypeFamilies #-}-{-# LANGUAGE TypeInType #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE UndecidableInstances #-} module VecTypes where