packages feed

eliminators 0.5 → 0.5.1

raw patch · 13 files changed

+221/−152 lines, 13 filesdep ~th-abstractionPVP: major bump suggested

API removals or changes: PVP suggests a major version bump

Dependency ranges changed: th-abstraction

API changes (from Hackage documentation)

- 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: elimBool :: forall (p_apkZ :: (~>) Bool Type) (s_apl0 :: Bool). Sing s_apl0 -> Apply p_apkZ 'False -> Apply p_apkZ 'True -> Apply p_apkZ s_apl0
- 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: elimEither :: forall (a_apl5 :: Type) (b_apl6 :: Type) (p_aplj :: (~>) (Either a_apl5 b_apl6) Type) (s_aplk :: Either a_apl5 b_apl6). Sing s_aplk -> (forall (f0_apll :: a_apl5). Sing f0_apll -> Apply p_aplj ( 'Left f0_apll)) -> (forall (f0_aplm :: b_apl6). Sing f0_aplm -> Apply p_aplj ( 'Right f0_aplm)) -> Apply p_aplj s_aplk
- 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: elimList :: forall (a_11 :: Type) (p_apPi :: (~>) ([] a_11) Type) (s_apPj :: [] a_11). Sing s_apPj -> Apply p_apPi '[] -> (forall (f0_apPk :: a_11). Sing f0_apPk -> forall (f1_apPl :: [a_11]). Sing f1_apPl -> Apply p_apPi f1_apPl -> Apply p_apPi ( '(:) f0_apPk f1_apPl)) -> Apply p_apPi s_apPj
- 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: elimMaybe :: forall (a_11 :: Type) (p_aplx :: (~>) (Maybe a_11) Type) (s_aply :: Maybe a_11). Sing s_aply -> Apply p_aplx 'Nothing -> (forall (f0_aplz :: a_11). Sing f0_aplz -> Apply p_aplx ( 'Just f0_aplz)) -> Apply p_aplx s_aply
- 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: elimNat :: forall (p_aplI :: (~>) Nat Type) (s_aplJ :: Nat). Sing s_aplJ -> Apply p_aplI 'Z -> (forall (f0_aplK :: Nat). Sing f0_aplK -> Apply p_aplI f0_aplK -> Apply p_aplI ( 'S f0_aplK)) -> Apply p_aplI s_aplJ
- 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: elimNonEmpty :: forall (a_ahw1 :: Type) (p_aplS :: (~>) (NonEmpty a_ahw1) Type) (s_aplT :: NonEmpty a_ahw1). Sing s_aplT -> (forall (f0_aplU :: a_ahw1). Sing f0_aplU -> forall (f1_aplV :: [a_ahw1]). Sing f1_aplV -> Apply p_aplS ( '(:|) f0_aplU f1_aplV)) -> Apply p_aplS s_aplT
- 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: elimOrdering :: forall (p_apm4 :: (~>) Ordering Type) (s_apm5 :: Ordering). Sing s_apm5 -> Apply p_apm4 'LT -> Apply p_apm4 'EQ -> Apply p_apm4 'GT -> Apply p_apm4 s_apm5
- Data.Eliminator: elimTuple0 :: forall (p_awDO :: (~>) () Type) (s_awDP :: ()). Sing s_awDP -> Apply p_awDO '() -> Apply p_awDO s_awDP
+ Data.Eliminator: elimTuple0 :: forall (p_apU3 :: (~>) () Type) (s_apU4 :: ()). Sing s_apU4 -> Apply p_apU3 '() -> Apply p_apU3 s_apU4
- 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: elimTuple2 :: forall (a_11 :: Type) (b_12 :: Type) (p_apU8 :: (~>) ((,) a_11 b_12) Type) (s_apU9 :: (,) a_11 b_12). Sing s_apU9 -> (forall (f0_apUa :: a_11). Sing f0_apUa -> forall (f1_apUb :: b_12). Sing f1_apUb -> Apply p_apU8 ( '(,) f0_apUa f1_apUb)) -> Apply p_apU8 s_apU9
- 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: elimTuple3 :: forall (a_11 :: Type) (b_12 :: Type) (c_13 :: Type) (p_apUk :: (~>) ((,,) a_11 b_12 c_13) Type) (s_apUl :: (,,) a_11 b_12 c_13). Sing s_apUl -> (forall (f0_apUm :: a_11). Sing f0_apUm -> forall (f1_apUn :: b_12). Sing f1_apUn -> forall (f2_apUo :: c_13). Sing f2_apUo -> Apply p_apUk ( '(,,) f0_apUm f1_apUn f2_apUo)) -> Apply p_apUk s_apUl
- 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: elimTuple4 :: forall (a_11 :: Type) (b_12 :: Type) (c_13 :: Type) (d_14 :: Type) (p_apUA :: (~>) ((,,,) a_11 b_12 c_13 d_14) Type) (s_apUB :: (,,,) a_11 b_12 c_13 d_14). Sing s_apUB -> (forall (f0_apUC :: a_11). Sing f0_apUC -> forall (f1_apUD :: b_12). Sing f1_apUD -> forall (f2_apUE :: c_13). Sing f2_apUE -> forall (f3_apUF :: d_14). Sing f3_apUF -> Apply p_apUA ( '(,,,) f0_apUC f1_apUD f2_apUE f3_apUF)) -> Apply p_apUA s_apUB
- 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: elimTuple5 :: forall (a_11 :: Type) (b_12 :: Type) (c_13 :: Type) (d_14 :: Type) (e_15 :: Type) (p_apUU :: (~>) ((,,,,) a_11 b_12 c_13 d_14 e_15) Type) (s_apUV :: (,,,,) a_11 b_12 c_13 d_14 e_15). Sing s_apUV -> (forall (f0_apUW :: a_11). Sing f0_apUW -> forall (f1_apUX :: b_12). Sing f1_apUX -> forall (f2_apUY :: c_13). Sing f2_apUY -> forall (f3_apUZ :: d_14). Sing f3_apUZ -> forall (f4_apV0 :: e_15). Sing f4_apV0 -> Apply p_apUU ( '(,,,,) f0_apUW f1_apUX f2_apUY f3_apUZ f4_apV0)) -> Apply p_apUU s_apUV
- 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: elimTuple6 :: forall (a_11 :: Type) (b_12 :: Type) (c_13 :: Type) (d_14 :: Type) (e_15 :: Type) (f_16 :: Type) (p_apVi :: (~>) ((,,,,,) a_11 b_12 c_13 d_14 e_15 f_16) Type) (s_apVj :: (,,,,,) a_11 b_12 c_13 d_14 e_15 f_16). Sing s_apVj -> (forall (f0_apVk :: a_11). Sing f0_apVk -> forall (f1_apVl :: b_12). Sing f1_apVl -> forall (f2_apVm :: c_13). Sing f2_apVm -> forall (f3_apVn :: d_14). Sing f3_apVn -> forall (f4_apVo :: e_15). Sing f4_apVo -> forall (f5_apVp :: f_16). Sing f5_apVp -> Apply p_apVi ( '(,,,,,) f0_apVk f1_apVl f2_apVm f3_apVn f4_apVo f5_apVp)) -> Apply p_apVi s_apVj
- 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: elimTuple7 :: forall (a_11 :: Type) (b_12 :: Type) (c_13 :: Type) (d_14 :: Type) (e_15 :: Type) (f_16 :: Type) (g_17 :: Type) (p_apVK :: (~>) ((,,,,,,) a_11 b_12 c_13 d_14 e_15 f_16 g_17) Type) (s_apVL :: (,,,,,,) a_11 b_12 c_13 d_14 e_15 f_16 g_17). Sing s_apVL -> (forall (f0_apVM :: a_11). Sing f0_apVM -> forall (f1_apVN :: b_12). Sing f1_apVN -> forall (f2_apVO :: c_13). Sing f2_apVO -> forall (f3_apVP :: d_14). Sing f3_apVP -> forall (f4_apVQ :: e_15). Sing f4_apVQ -> forall (f5_apVR :: f_16). Sing f5_apVR -> forall (f6_apVS :: g_17). Sing f6_apVS -> Apply p_apVK ( '(,,,,,,) f0_apVM f1_apVN f2_apVO f3_apVP f4_apVQ f5_apVR f6_apVS)) -> Apply p_apVK s_apVL
- Data.Eliminator: elimVoid :: forall (p_aw61 :: (~>) Void Type) (s_aw62 :: Void). Sing s_aw62 -> Apply p_aw61 s_aw62
+ Data.Eliminator: elimVoid :: forall (p_apmf :: (~>) Void Type) (s_apmg :: Void). Sing s_apmg -> Apply p_apmf s_apmg

Files

CHANGELOG.md view
@@ -1,3 +1,6 @@+### 0.5.1 [2019.04.26]+* Support `th-abstraction-0.3.0.0` or later.+ ## 0.5 [2018.09.18] * Require `singletons-2.5` and GHC 8.6. 
eliminators.cabal view
@@ -1,5 +1,5 @@ name:                eliminators-version:             0.5+version:             0.5.1 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.6.1+tested-with:         GHC == 8.6.4  source-repository head   type:                git@@ -26,16 +26,16 @@   exposed-modules:     Data.Eliminator                        Data.Eliminator.TH                        Data.Eliminator.TypeNats-  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+  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.11 && < 0.4+                     , th-desugar       >= 1.9    && < 1.10   hs-source-dirs:      src   default-language:    Haskell2010-  ghc-options:         -Wall -Wno-unticked-promoted-constructors+  ghc-options:         -Wall -Wcompat -Wno-unticked-promoted-constructors  test-suite spec   type:                exitcode-stdio-1.0@@ -45,6 +45,7 @@                        EqualitySpec                        EqualityTypes                        GADTSpec+                       Internal                        ListSpec                        ListTypes                        VecTypes@@ -57,4 +58,4 @@   build-tool-depends:  hspec-discover:hspec-discover   hs-source-dirs:      tests   default-language:    Haskell2010-  ghc-options:         -Wall -Wno-unticked-promoted-constructors -threaded -rtsopts+  ghc-options:         -Wall -Wcompat -Wno-unticked-promoted-constructors -threaded -rtsopts
src/Data/Eliminator/TH.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE TemplateHaskell #-} {-# LANGUAGE Unsafe #-} {-|@@ -29,7 +30,7 @@  import           Language.Haskell.TH import           Language.Haskell.TH.Datatype-import           Language.Haskell.TH.Desugar (tupleNameDegree_maybe, unboxedTupleNameDegree_maybe)+import           Language.Haskell.TH.Desugar hiding (NewOrData(..))  {- $conventions 'deriveElim' and 'deriveElimNamed' provide a way to automate the creation of@@ -149,7 +150,12 @@ -- function named @funName@ for the datatype @dataName@. deriveElimNamed :: String -> Name -> Q [Dec] deriveElimNamed funName dataName = do-  info@(DatatypeInfo { datatypeVars    = vars+  info@(DatatypeInfo { datatypeVars    =+#if MIN_VERSION_th_abstraction(0,3,0)+                                         dataVarBndrs+#else+                                         dataVars+#endif                      , datatypeVariant = variant                      , datatypeCons    = cons                      }) <- reifyDatatype dataName@@ -163,7 +169,9 @@   predVar <- newName "p"   singVar <- newName "s"   let elimN = mkName funName-      dataVarBndrs = catMaybes $ map typeToTyVarBndr vars+#if !(MIN_VERSION_th_abstraction(0,3,0))+      dataVarBndrs = freeVariablesWellScoped dataVars+#endif       promDataKind = datatypeType info       predVarBndr = KindedTV predVar (InfixT promDataKind ''(~>) (ConT ''Kind.Type))       singVarBndr = KindedTV singVar promDataKind@@ -283,10 +291,6 @@   = "~>" ++ nStr   where     nStr = nameBase n--typeToTyVarBndr :: Type -> Maybe TyVarBndr-typeToTyVarBndr (SigT (VarT n) k) = Just $ KindedTV n k-typeToTyVarBndr _                 = Nothing  -- Reconstruct and arrow type from the list of types ravel :: [Type] -> Type -> Type
tests/DecideSpec.hs view
@@ -114,7 +114,7 @@                  -> Decision (S k :~: S m)         stepStep sm _ = decCongS sk (runWhyDecEqNat swhyK sm) -listEqConsequencesSame :: forall (es :: [e]). Sing es -> ListEqConsequences es es+listEqConsequencesSame :: forall e (es :: [e]). Sing es -> ListEqConsequences es es listEqConsequencesSame sl = elimList @e @WhyListEqConsequencesSameSym0 @es sl base step   where     base :: ListEqConsequences '[] '[]@@ -126,24 +126,24 @@          -> ListEqConsequences (x:xs) (x:xs)     step _ _ _ = (Refl, Refl) -useListEq :: forall (xs :: [e]) (ys :: [e]).+useListEq :: forall e (xs :: [e]) (ys :: [e]).              Sing xs -> xs :~: ys -> ListEqConsequences xs ys useListEq sxs xsEqYs = replace @[e] @xs @ys @(ListEqConsequencesSym1 xs)                                (listEqConsequencesSame @e @xs sxs) xsEqYs -nilNotCons :: forall (x :: e) (xs :: [e]). '[] :~: (x:xs) -> Void+nilNotCons :: forall e (x :: e) (xs :: [e]). '[] :~: (x:xs) -> Void nilNotCons = useListEq @e @'[] @(x:xs) SNil -consNotNil :: forall (x :: e) (xs :: [e]). (x:xs) :~: '[] -> Void+consNotNil :: forall e (x :: e) (xs :: [e]). (x:xs) :~: '[] -> Void consNotNil eq = nilNotCons @e @x @xs (sym eq) -consInjective :: forall (x :: e) (xs :: [e]) (y :: e) (ys :: [e]).+consInjective :: forall e (x :: e) (xs :: [e]) (y :: e) (ys :: [e]).                  Sing x -> Sing xs               -> (x:xs) :~: (y:ys)               -> (x :~: y, xs :~: ys) consInjective sx sxs = useListEq @e @(x:xs) @(y:ys) (SCons sx sxs) -decEqNil :: forall (es :: [e]). Sing es -> Decision ('[] :~: es)+decEqNil :: forall e (es :: [e]). Sing es -> Decision ('[] :~: es) decEqNil ses = elimList @e @WhyDecEqNilSym0 @es ses base step   where     base :: Decision ('[] :~: '[])@@ -155,7 +155,7 @@          -> Decision ('[] :~: (x:xs))     step _ _ _ = Disproved (nilNotCons @e @x @xs) -intermixListEqs :: forall (x :: e) (xs :: [e]) (y :: e) (ys :: [e]).+intermixListEqs :: forall e (x :: e) (xs :: [e]) (y :: e) (ys :: [e]).                    x :~: y -> xs :~: ys                 -> (x:xs) :~: (y:ys) intermixListEqs xEqY xsEqYs =@@ -163,7 +163,7 @@           (replace @[e] @xs @ys @(WhyIntermixListEqs2Sym2 x xs) Refl xsEqYs)           xEqY -decCongCons :: forall (x :: e) (xs :: [e]) (y :: e) (ys :: [e]).+decCongCons :: forall e (x :: e) (xs :: [e]) (y :: e) (ys :: [e]).                Sing x -> Sing xs             -> Decision (x :~: y) -> Decision (xs :~: ys)             -> Decision ((x:xs) :~: (y:ys))@@ -193,7 +193,7 @@     injective :: (x:xs) :~: (y:ys) -> (x :~: y, xs :~: ys)     injective = consInjective @e @x @xs @y @ys sx sxs -decEqList :: forall (es1 :: [e]) (es2 :: [e]).+decEqList :: forall e (es1 :: [e]) (es2 :: [e]).              (forall (e1 :: e) (e2 :: e).                      Sing e1 -> Sing e2 -> Decision (e1 :~: e2))           -> Sing es1 -> Sing es2 -> Decision (es1 :~: es2)
tests/DecideTypes.hs view
@@ -23,10 +23,10 @@   = Proved a   | Disproved (p @@ a @@ Void) -elimDecision :: forall (a :: Type) (p :: PDecision a ~> Type) (d :: PDecision a).+elimDecision :: forall a (p :: PDecision a ~> Type) (d :: PDecision a).                 Sing d-             -> (forall (yes :: a). Sing yes -> p @@ (Proved yes))-             -> (forall (no :: a ~> Void). Sing no -> p @@ (Disproved no))+             -> (forall (yes :: a). Sing yes -> p @@ Proved yes)+             -> (forall (no :: a ~> Void). Sing no -> p @@ Disproved no)              -> p @@ d elimDecision (SProved yes)   pProved _          = pProved yes elimDecision (SDisproved no) _       pDisproved = pDisproved no@@ -40,12 +40,12 @@ type Decision  = Decision' (TyCon (->)) type PDecision = Decision' (~>@#@$) -data instance Sing (z :: PDecision a) where+data instance Sing :: forall a. PDecision a -> Type where   -- It would be lovely to not have to write those (:: PDecision a) kind   -- ascriptions in the return types of each constructor.   -- See https://ghc.haskell.org/trac/ghc/ticket/14111.-  SProved    :: forall (x :: a).         Sing x -> Sing (Proved x    :: PDecision a)-  SDisproved :: forall (r :: a ~> Void). Sing r -> Sing (Disproved r :: PDecision a)+  SProved    :: forall a (x :: a).         Sing x -> Sing (Proved x    :: PDecision a)+  SDisproved :: forall a (r :: a ~> Void). Sing r -> Sing (Disproved r :: PDecision a)  instance SingKind a => SingKind (PDecision a) where   type Demote (PDecision a) = Decision (Demote a)@@ -54,46 +54,41 @@   toSing (Proved x)    = withSomeSing x $ SomeSing . SProved   toSing (Disproved r) = withSomeSing r $ SomeSing . SDisproved -type family NatEqConsequences (a :: Nat) (b :: Nat) :: Type where-  NatEqConsequences Z      Z      = ()-  NatEqConsequences Z      (S _)  = Void-  NatEqConsequences (S _)  Z      = Void-  NatEqConsequences (S k1) (S k2) = k1 :~: k2-$(genDefunSymbols [''NatEqConsequences])+$(singletons [d|+  type family NatEqConsequences (a :: Nat) (b :: Nat) :: Type where+    NatEqConsequences Z      Z      = ()+    NatEqConsequences Z      (S _)  = Void+    NatEqConsequences (S _)  Z      = Void+    NatEqConsequences (S k1) (S k2) = k1 :~: k2 -type WhyNatEqConsequencesSame (a :: Nat) = NatEqConsequences a a-$(genDefunSymbols [''WhyNatEqConsequencesSame])+  type WhyNatEqConsequencesSame (a :: Nat) = NatEqConsequences a a -type WhyDecEqZ (k :: Nat) = Decision (Z :~: k)-$(genDefunSymbols [''WhyDecEqZ])+  type WhyDecEqZ (k :: Nat) = Decision (Z :~: k) -type WhyDecEqS (n :: Nat) (k :: Nat) = Decision (S n :~: k)-$(genDefunSymbols [''WhyDecEqS])+  type WhyDecEqS (n :: Nat) (k :: Nat) = Decision (S n :~: k)+  |])  -- The newtype wrapper is needed to work around -- https://github.com/goldfirere/singletons/issues/198 newtype WhyDecEqNat (k :: Nat) = WhyDecEqNat   { runWhyDecEqNat :: forall (j :: Nat). Sing j -> Decision (k :~: j) } -type family ListEqConsequences (xxs :: [e]) (yys :: [e]) :: Type where-  ListEqConsequences '[]    '[]    = ()-  ListEqConsequences '[]    (_:_)  = Void-  ListEqConsequences (_:_)  '[]    = Void-  ListEqConsequences (x:xs) (y:ys) = (x :~: y, xs :~: ys)-$(genDefunSymbols [''ListEqConsequences])+$(singletons [d|+  type family ListEqConsequences (xxs :: [e]) (yys :: [e]) :: Type where+    ListEqConsequences '[]    '[]    = ()+    ListEqConsequences '[]    (_:_)  = Void+    ListEqConsequences (_:_)  '[]    = Void+    ListEqConsequences (x:xs) (y:ys) = (x :~: y, xs :~: ys) -type WhyListEqConsequencesSame (es :: [e]) = ListEqConsequences es es-$(genDefunSymbols [''WhyListEqConsequencesSame])+  type WhyListEqConsequencesSame (es :: [e]) = ListEqConsequences es es -type WhyDecEqNil (es :: [e]) = Decision ('[] :~: es)-$(genDefunSymbols [''WhyDecEqNil])+  type WhyDecEqNil (es :: [e]) = Decision ('[] :~: es) -type WhyDecEqCons (x :: e) (xs :: [e]) (es :: [e]) = Decision ((x:xs) :~: es)-$(genDefunSymbols [''WhyDecEqCons])+  type WhyDecEqCons (x :: e) (xs :: [e]) (es :: [e]) = Decision ((x:xs) :~: es) -type WhyIntermixListEqs1 (x :: e) (xs :: [e]) (ys :: [e]) (k :: e) = (x:xs) :~: (k:ys)-type WhyIntermixListEqs2 (x :: e) (xs :: [e]) (k :: [e])           = (x:xs) :~: (x:k)-$(genDefunSymbols [''WhyIntermixListEqs1, ''WhyIntermixListEqs2])+  type WhyIntermixListEqs1 (x :: e) (xs :: [e]) (ys :: [e]) (k :: e) = (x:xs) :~: (k:ys)+  type WhyIntermixListEqs2 (x :: e) (xs :: [e]) (k :: [e])           = (x:xs) :~: (x:k)+  |])  -- The newtype wrapper is needed to work around -- https://github.com/goldfirere/singletons/issues/198
tests/EqualitySpec.hs view
@@ -16,6 +16,7 @@ import           Data.Type.Equality ((:~:)(..), (:~~:)(..))  import           EqualityTypes+import           Internal  import           Test.Hspec @@ -33,23 +34,37 @@  ----- -j :: forall (k :: Type) (a :: k) (b :: k)-            (p :: forall (x :: k) (y :: k). x :~: y ~> Type)+j :: forall k (p :: forall (x :: k) (y :: k). x :~: y ~> Type)+            (a :: k) (b :: k)             (r :: a :~: b).      Sing r   -> (forall (x :: k). p @@ (Refl :: x :~: x))   -> p @@ r j SRefl pRefl = pRefl @a -hj :: forall (j :: Type) (k :: Type) (a :: j) (b :: k)-             (p :: forall (y :: Type) (z :: Type) (w :: y) (x :: z). w :~~: x ~> Type)+jProp :: forall k (p :: k ~> k ~> Prop)+                (a :: k) (b :: k).+         a :~: b+      -> (forall (x :: k). p @@ x @@ x)+      -> p @@ a @@ b+jProp Refl pRefl = pRefl @a++hj :: forall (p :: forall y z (w :: y) (x :: z). w :~~: x ~> Type)+             j k (a :: j) (b :: k)              (r :: a :~~: b).       Sing r-   -> (forall (y :: Type) (w :: y). p @@ (HRefl :: w :~~: w))+   -> (forall y (w :: y). p @@ (HRefl :: w :~~: w))    -> p @@ r-hj SHRefl pHRefl = pHRefl @k @a+hj SHRefl pHRefl = pHRefl @j @a -k :: forall (k :: Type) (a :: k)+hjProp :: forall (p :: forall y z. y ~> z ~> Prop)+                 j k (a :: j) (b :: k).+          a :~~: b+       -> (forall y (w :: y). p @@ w @@ w)+       -> p @@ a @@ b+hjProp HRefl pHRefl = pHRefl @j @a++k :: forall k (a :: k)             (p :: a :~: a ~> Type)             (r :: a :~: a).      Sing r@@ -57,7 +72,7 @@   -> p @@ r k SRefl pRefl = pRefl -hk :: forall (k :: Type) (a :: k)+hk :: forall k (a :: k)              (p :: a :~~: a ~> Type)              (r :: a :~~: a).       Sing r@@ -65,64 +80,64 @@    -> p @@ r hk SHRefl pHRefl = pHRefl -sym :: forall (t :: Type) (a :: t) (b :: t).+sym :: forall t (a :: t) (b :: t).        a :~: b -> b :~: a sym eq = withSomeSing eq $ \(singEq :: Sing r) ->-           (~>:~:) @t @a @b @(WhySymSym1 a) @r singEq Refl+           (~>:~:) @t @a @(WhySymSym1 a) @b @r singEq Refl -hsym :: forall (j :: Type) (k :: Type) (a :: j) (b :: k).+hsym :: forall j k (a :: j) (b :: k).         a :~~: b -> b :~~: a hsym eq = withSomeSing eq $ \(singEq :: Sing r) ->-            (~>:~~:) @j @k @a @b @(WhyHsymSym1 a) @r singEq HRefl+            (~>:~~:) @j @a @(WhyHsymSym1 a) @k @b @r singEq HRefl -symIdempotent :: forall (t :: Type) (a :: t) (b :: t)+symIdempotent :: forall t (a :: t) (b :: t)                         (e :: a :~: b).                  Sing e -> Symmetry (Symmetry e) :~: e-symIdempotent se = (~>:~:) @t @a @b @(WhySymIdempotentSym1 a) @e se Refl+symIdempotent se = (~>:~:) @t @a @(WhySymIdempotentSym1 a) @b @e se Refl -hsymIdempotent :: forall (j :: Type) (k :: Type) (a :: j) (b :: k)+hsymIdempotent :: forall j k (a :: j) (b :: k)                          (e :: a :~~: b).                   Sing e -> Hsymmetry (Hsymmetry e) :~: e-hsymIdempotent se = (~>:~~:) @j @k @a @b @(WhyHsymIdempotentSym1 a) @e se Refl+hsymIdempotent se = (~>:~~:) @j @a @(WhyHsymIdempotentSym1 a) @k @b @e se Refl -replace :: forall (t :: Type) (from :: t) (to :: t) (p :: t ~> Type).+replace :: forall t (from :: t) (to :: t) (p :: t ~> Type).            p @@ from         -> from :~: to         -> p @@ to replace from eq =   withSomeSing eq $ \(singEq :: Sing r) ->-    (~>:~:) @t @from @to @(WhyReplaceSym2 from p) @r singEq from+    (~>:~:) @t @from @(WhyReplaceSym2 from p) @to @r singEq from  -- Doesn't work due to https://ghc.haskell.org/trac/ghc/ticket/11719 {--hreplace :: forall (j :: Type) (k :: Type) (from :: j) (to :: k)-                   (p :: forall (z :: Type). z ~> Type).+hreplace :: forall j k (from :: j) (to :: k)+                   (p :: forall z. z ~> Type).             p @@ from          -> from :~~: to          -> p @@ to hreplace from heq =-  withSomeSing eq $ \(singEq :: Sing r) ->-    (@~>:~~:) @j @k @from @to @(WhyHreplaceSym2 from p) singEq from+  withSomeSing heq $ \(singEq :: Sing r) ->+    (~>:~~:) @j @from @(WhyHreplaceSym2 from p) @k @to @r singEq from -} -leibniz :: forall (t :: Type) (f :: t ~> Type) (a :: t) (b :: t).+leibniz :: forall t (f :: t ~> Type) (a :: t) (b :: t).            a :~: b         -> f @@ a         -> f @@ b leibniz = replace @t @a @b @(WhyLeibnizSym2 f a) id -cong :: forall (x :: Type) (y :: Type) (f :: x ~> y)+cong :: forall x y (f :: x ~> y)                (a :: x) (b :: x).         a :~: b      -> f @@ a :~: f @@ b cong eq =   withSomeSing eq $ \(singEq :: Sing r) ->-    (~>:~:) @x @a @b @(WhyCongSym2 f a) @r singEq Refl+    (~>:~:) @x @a @(WhyCongSym2 f a) @b @r singEq Refl -eqIsRefl :: forall (k :: Type) (a :: k) (b :: k) (e :: a :~: b).+eqIsRefl :: forall k (a :: k) (b :: k) (e :: a :~: b).             Sing e -> e :~~: (Refl :: a :~: a)-eqIsRefl eq = (~>:~:) @k @a @b @(WhyEqIsReflSym1 a) @e eq HRefl+eqIsRefl eq = (~>:~:) @k @a @(WhyEqIsReflSym1 a) @b @e eq HRefl -heqIsHRefl :: forall (j :: Type) (k :: Type) (a :: j) (b :: k) (e :: a :~~: b).+heqIsHRefl :: forall j k (a :: j) (b :: k) (e :: a :~~: b).               Sing e -> e :~~: (HRefl :: a :~~: a)-heqIsHRefl heq = (~>:~~:) @j @k @a @b @(WhyHEqIsHReflSym1 a) @e heq HRefl+heqIsHRefl heq = (~>:~~:) @j @a @(WhyHEqIsHReflSym1 a) @k @b @e heq HRefl
tests/EqualityTypes.hs view
@@ -16,7 +16,9 @@ import           Data.Singletons.TH import           Data.Type.Equality ((:~:)(..), (:~~:)(..)) -data instance Sing (z :: a :~: b) where+import           Internal++data instance Sing :: forall k (a :: k) (b :: k). a :~: b -> Type where   SRefl :: Sing Refl type (%:~:) = (Sing :: (a :: k) :~: (b :: k) -> Type) @@ -29,15 +31,23 @@   sing = SRefl  -- | Christine Paulin-Mohring's version of the J rule.-(~>:~:) :: forall (k :: Type) (a :: k) (b :: k)+(~>:~:) :: forall k (a :: k)                   (p :: forall (y :: k). a :~: y ~> Type)-                  (r :: a :~: b).+                  (b :: k) (r :: a :~: b).            Sing r         -> p @@ Refl         -> p @@ r (~>:~:) SRefl pRefl = pRefl -data instance Sing (z :: a :~~: b) where+(~>!:~:) :: forall k (a :: k)+                   (p :: k ~> Prop)+                   (b :: k).+            a :~: b+         -> p @@ a+         -> p @@ b+(~>!:~:) Refl pRefl = pRefl++data instance Sing :: forall j k (a :: j) (b :: k). a :~~: b -> Type where   SHRefl :: Sing HRefl type (%:~~:) = (Sing :: (a :: j) :~~: (b :: k) -> Type) @@ -50,14 +60,22 @@   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).+(~>:~~:) :: forall j (a :: j)+                   (p :: forall z (y :: z). a :~~: y ~> Type)+                   k (b :: k) (r :: a :~~: b).             Sing r          -> p @@ HRefl          -> p @@ r (~>:~~:) SHRefl pHRefl = pHRefl +(~>!:~~:) :: forall j (a :: j)+                    (p :: forall z. z ~> Prop)+                    k (b :: k).+             a :~~: b+          -> p @@ a+          -> p @@ b+(~>!:~~:) HRefl pHRefl = pHRefl+ -----  $(singletons [d|@@ -85,7 +103,7 @@    -- Doesn't work due to https://ghc.haskell.org/trac/ghc/ticket/11719   {--  type family WhyHreplace (from :: j) (p :: forall (z :: Type). z ~> Type)+  type family WhyHreplace (from :: j) (p :: forall z. z ~> Type)                           (e :: from :~~: (y :: k)) :: Type where     WhyHreplace from p (_ :: from :~~: y) = p @@ y   -}
tests/GADTSpec.hs view
@@ -12,6 +12,8 @@ import Data.Kind import Data.Singletons +import Internal+ import Test.Hspec  main :: IO ()@@ -25,31 +27,37 @@ data So :: Bool -> Type where   Oh :: So True -data instance Sing (z :: So what) where+data instance Sing :: forall (what :: Bool). So what -> Type where   SOh :: Sing Oh type SSo = (Sing :: So what -> Type) -elimSo :: forall (what :: Bool) (s :: So what) (p :: forall (long_sucker :: Bool). So long_sucker ~> Type).+elimSo :: forall (p :: forall (long_sucker :: Bool). So long_sucker ~> Type)+                 (what :: Bool) (s :: So what).           Sing s        -> p @@ Oh        -> p @@ s elimSo SOh pOh = pOh -data Flarble (a :: Type) (b :: Type) where+elimPropSo :: forall (p :: Bool ~> Prop) (what :: Bool).+              So what+           -> p @@ True+           -> p @@ what+elimPropSo Oh pOh = pOh++data Flarble :: Type -> Type -> Type where   MkFlarble1 :: a -> Flarble a b   MkFlarble2 :: a ~ Bool => Flarble a (Maybe b) -data instance Sing (z :: Flarble a b) where+data instance Sing :: forall a b. Flarble a b -> Type where   SMkFlarble1 :: Sing x -> Sing (MkFlarble1 x)   SMkFlarble2 :: Sing MkFlarble2 type SFlarble = (Sing :: Flarble a b -> Type) -elimFlarble :: forall (a :: Type) (b :: Type)-                      (p :: forall (x :: Type) (y :: Type). Flarble x y ~> Type)-                      (f :: Flarble a b).+elimFlarble :: forall (p :: forall x y. Flarble x y ~> Type)+                      a b (f :: Flarble a b).                Sing f-            -> (forall (a' :: Type) (b' :: Type) (x :: a'). Sing x -> p @@ (MkFlarble1 x :: Flarble a' b'))-            -> (forall (b' :: Type). p @@ (MkFlarble2 :: Flarble Bool (Maybe b')))+            -> (forall a' b' (x :: a'). Sing x -> p @@ (MkFlarble1 x :: Flarble a' b'))+            -> (forall b'. p @@ (MkFlarble2 :: Flarble Bool (Maybe b')))             -> p @@ f elimFlarble s@(SMkFlarble1 sx) pMkFlarble1 _ =   case s of@@ -58,15 +66,33 @@   case s of     (_ :: Sing (MkFlarble2 :: Flarble Bool (Maybe b'))) -> pMkFlarble2 @b' +elimPropFlarble :: forall (p :: Type ~> Type ~> Prop) a b.+                   Flarble a b+                -> (forall a' b'. a -> p @@ a' @@ b')+                -> (forall b'. p @@ Bool @@ Maybe b')+                -> p @@ a @@ b+elimPropFlarble f@(MkFlarble1 x) pMkFlarble1 _ =+  case f of+    (_ :: Flarble a' b') -> pMkFlarble1 @a' @b' x+elimPropFlarble f@MkFlarble2 _ pMkFlarble2 =+  case f of+    (_ :: Flarble Bool (Maybe b')) -> pMkFlarble2 @b'+ data Obj :: Type where   MkObj :: o -> Obj -data instance Sing (z :: Obj) where-  SMkObj :: forall (obj :: obiwan). Sing obj -> Sing (MkObj obj)+data instance Sing :: Obj -> Type where+  SMkObj :: forall obiwan (obj :: obiwan). Sing obj -> Sing (MkObj obj) type SObj = (Sing :: Obj -> Type) -elimObj :: forall (o :: Obj) (p :: Obj ~> Type).+elimObj :: forall (p :: Obj ~> Type) (o :: Obj).            Sing o-        -> (forall (obj :: Type) (x :: obj). Sing x -> p @@ (MkObj x))+        -> (forall obj (x :: obj). Sing x -> p @@ MkObj x)         -> p @@ o-elimObj (SMkObj (x :: Sing (obj :: obiwan))) pMkObj = pMkObj @obiwan @obj x+elimObj (SMkObj (sx :: Sing (x :: obj))) pMkObj = pMkObj @obj @x sx++elimPropObj :: forall (p :: Prop).+               Obj+            -> (forall obj. obj -> p)+            -> p+elimPropObj (MkObj o) pMkObj = pMkObj o
+ tests/Internal.hs view
@@ -0,0 +1,5 @@+module Internal where++import Data.Kind++type Prop = Type
tests/ListSpec.hs view
@@ -10,7 +10,6 @@ module ListSpec where  import Data.Eliminator-import Data.Kind import Data.Singletons.Prelude import Data.Singletons.Prelude.List import Data.Type.Equality@@ -29,7 +28,7 @@  ----- -mapPreservesLength :: forall (x :: Type) (y :: Type) (f :: x ~> y) (l :: [x]).+mapPreservesLength :: forall x y (f :: x ~> y) (l :: [x]).                       SingI l                    => Length l :~: Length (Map f l) mapPreservesLength@@ -44,7 +43,7 @@          -> WhyMapPreservesLength f (s:ss)     step _ _ = cong @_ @_ @((+@#@$$) 1) -mapFusion :: forall (x :: Type) (y :: Type) (z :: Type)+mapFusion :: forall x y z                     (f :: y ~> z) (g :: x ~> y) (l :: [x]).                     SingI l                  => Map f (Map g l) :~: Map (f .@#@$$$ g) l
tests/ListTypes.hs view
@@ -11,10 +11,10 @@ import Data.Singletons.Prelude.List import Data.Singletons.TH -type WhyMapPreservesLength (f :: x ~> y) (l :: [x])-  = Length l :~: Length (Map f l)-$(genDefunSymbols [''WhyMapPreservesLength])+$(singletons [d|+  type WhyMapPreservesLength (f :: x ~> y) (l :: [x])+    = Length l :~: Length (Map f l) -type WhyMapFusion (f :: y ~> z) (g :: x ~> y) (l :: [x])-  = Map f (Map g l) :~: Map (f .@#@$$$ g) l-$(genDefunSymbols [''WhyMapFusion])+  type WhyMapFusion (f :: y ~> z) (g :: x ~> y) (l :: [x])+    = Map f (Map g l) :~: Map (f .@#@$$$ g) l+  |])
tests/VecSpec.hs view
@@ -8,7 +8,6 @@ module VecSpec where  import Data.Eliminator-import Data.Kind (Type) import Data.Nat import Data.Singletons import Data.Singletons.Prelude.Num@@ -69,14 +68,14 @@  ----- -replicateVec :: forall (e :: Type) (howMany :: Nat).+replicateVec :: forall e (howMany :: Nat).                 Sing howMany -> e -> Vec e howMany replicateVec s e = elimNat @(TyCon (Vec e)) @howMany s VNil step   where     step :: forall (k :: Nat). Sing k -> Vec e k -> Vec e (S k)     step _ = (e :#) -mapVec :: forall (a :: Type) (b :: Type) (n :: Nat).+mapVec :: forall a b (n :: Nat).           SingI n        => (a -> b) -> Vec a n -> Vec b n mapVec f = elimNat @(WhyMapVecSym2 a b) @n (sing @n) base step@@ -87,7 +86,7 @@     step :: forall (k :: Nat). Sing k -> WhyMapVec a b k -> WhyMapVec a b (S k)     step _ mapK vK = f (vhead vK) :# mapK (vtail vK) -zipWithVec :: forall (a :: Type) (b :: Type) (c :: Type) (n :: Nat).+zipWithVec :: forall a b c (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@@ -102,7 +101,7 @@     step _ zwK vaK vbK = f   (vhead vaK) (vhead vbK)                       :# zwK (vtail vaK) (vtail vbK) -appendVec :: forall (e :: Type) (n :: Nat) (m :: Nat).+appendVec :: forall e (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@@ -116,7 +115,7 @@          -> WhyAppendVec e m (S k)     step _ avK vK1 vK2 = vhead vK1 :# avK (vtail vK1) vK2 -transposeVec :: forall (e :: Type) (n :: Nat) (m :: Nat).+transposeVec :: forall e (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@@ -130,17 +129,17 @@          -> WhyTransposeVec e m (S k)     step _ transK vK = zipWithVec (:#) (vhead vK) (transK (vtail vK)) -concatVec :: forall (e :: Type) (n :: Nat) (j :: Nat).+concatVec :: forall e (n :: Nat) (j :: Nat).              (SingKind e, SingI j, e ~ Demote e)           => Vec (Vec e j) n -> Vec e (n * j) concatVec l = withSomeSing l $ \(singL :: Sing l) ->-                elimVec @(Vec e j) @n @(WhyConcatVecSym e j) @l singL base step+                elimVec @(Vec e j) @(WhyConcatVecSym2 e j) @n @l singL base step   where-    base :: WhyConcatVec e j Z VNil+    base :: WhyConcatVec e j VNil     base = VNil      step :: forall (k :: Nat) (x :: Vec e j) (xs :: Vec (Vec e j) k).                    Sing x -> Sing xs-                -> WhyConcatVec e j k     xs-                -> WhyConcatVec e j (S k) (x :# xs)+                -> WhyConcatVec e j xs+                -> WhyConcatVec e j (x :# xs)     step h _ vKJ = appendVec (fromSing h) vKJ
tests/VecTypes.hs view
@@ -17,6 +17,7 @@ import Data.Nat import Data.Singletons.Prelude.Num import Data.Singletons.TH+import Internal  data Vec :: Type -> Nat -> Type where   VNil :: Vec a Z@@ -26,7 +27,7 @@ deriving instance Ord a  => Ord (Vec a n) deriving instance Show a => Show (Vec a n) -data instance Sing (z :: Vec a n) where+data instance Sing :: forall a (n :: Nat). Vec a n -> Type where   SVNil :: Sing VNil   (:%#) :: { sVhead :: Sing x, sVtail :: Sing xs } -> Sing (x :# xs) type SVec = (Sing :: Vec a n -> Type)@@ -48,8 +49,8 @@ instance (SingI x, SingI xs) => SingI (x :# xs) where   sing = sing :%# sing -elimVec :: forall (a :: Type) (n :: Nat)-                  (p :: forall (k :: Nat). Vec a k ~> Type) (v :: Vec a n).+elimVec :: forall a (p :: forall (k :: Nat). Vec a k ~> Type)+                  (n :: Nat) (v :: Vec a n).            Sing v         -> p @@ VNil         -> (forall (k :: Nat) (x :: a) (xs :: Vec a k).@@ -57,26 +58,29 @@         -> p @@ v elimVec SVNil pVNil _ = pVNil elimVec (sx :%# (sxs :: Sing (xs :: Vec a k))) pVNil pVCons =-  pVCons sx sxs (elimVec @a @k @p @xs sxs pVNil pVCons)+  pVCons sx sxs (elimVec @a @p @k @xs sxs pVNil pVCons) -type WhyMapVec (a :: Type) (b :: Type) (n :: Nat) = Vec a n -> Vec b n-$(genDefunSymbols [''WhyMapVec])+elimPropVec :: forall a (p :: Nat ~> Prop) (n :: Nat).+               Vec a n+            -> p @@ Z+            -> (forall (k :: Nat). a -> Vec a k -> p @@ k -> p @@ S k)+            -> p @@ n+elimPropVec VNil pZ _ = pZ+elimPropVec (x :# (xs :: Vec a k)) pZ pS =+  pS x xs (elimPropVec @a @p @k xs pZ pS) -type WhyZipWithVec (a :: Type) (b :: Type) (c :: Type) (n :: Nat)-  = Vec a n -> Vec b n -> Vec c n-$(genDefunSymbols [''WhyZipWithVec])+$(singletons [d|+  type WhyMapVec a b (n :: Nat) = Vec a n -> Vec b n -type WhyAppendVec (e :: Type) (m :: Nat) (n :: Nat)-  = Vec e n -> Vec e m -> Vec e (n + m)-$(genDefunSymbols [''WhyAppendVec])+  type WhyZipWithVec a b c (n :: Nat)+    = Vec a n -> Vec b n -> Vec c n -type WhyTransposeVec (e :: Type) (m :: Nat) (n :: Nat)-  = Vec (Vec e m) n -> Vec (Vec e n) m-$(genDefunSymbols [''WhyTransposeVec])+  type WhyAppendVec e (m :: Nat) (n :: Nat)+    = Vec e n -> Vec e m -> Vec e (n + m) -type WhyConcatVec (e :: Type) (j :: Nat) (n :: Nat) (l :: Vec (Vec e j) n)-  = Vec e (n * j)-data WhyConcatVecSym (e :: Type) (j :: Nat)-  :: forall (n :: Nat). Vec (Vec e j) n ~> Type-type instance Apply (WhyConcatVecSym e j :: Vec (Vec e j) n ~> Type) l-  = WhyConcatVec e j n l+  type WhyTransposeVec e (m :: Nat) (n :: Nat)+    = Vec (Vec e m) n -> Vec (Vec e n) m++  type family WhyConcatVec e (j :: Nat) (l :: Vec (Vec e j) n) :: Type where+    WhyConcatVec e j (l :: Vec (Vec e j) n) = Vec e (n * j)+  |])