1- {-# LANGUAGE DataKinds #-}
21{-# LANGUAGE GADTs #-}
32{-# LANGUAGE KindSignatures #-}
43{-# LANGUAGE LambdaCase #-}
@@ -11,7 +10,8 @@ module Analysis.Syntax
1110 Term (.. )
1211, subterms
1312 -- * Vectors
14- , Nat (.. )
13+ , Z
14+ , S
1515, N0
1616, N1
1717, N2
@@ -29,7 +29,7 @@ import Unsafe.Coerce (unsafeCoerce)
2929-- Syntax
3030
3131-- | (Currently) untyped term representations.
32- data Term (sig :: Nat -> Type ) v where
32+ data Term (sig :: Type -> Type ) v where
3333 Var :: v -> Term sig v
3434 (:$:) :: KnownNat n => sig n -> Vec n (Term sig v ) -> Term sig v
3535
@@ -57,26 +57,24 @@ subterms t = case t of
5757
5858-- Vectors
5959
60- data Nat
61- = Z
62- | S Nat
63- deriving (Eq , Ord , Show )
60+ data Z
61+ data S n
6462
65- type N0 = ' Z
66- type N1 = ' S N0
67- type N2 = ' S N1
68- type N3 = ' S N2
63+ type N0 = Z
64+ type N1 = S N0
65+ type N2 = S N1
66+ type N3 = S N2
6967
7068
7169-- | Reify 'Nat's back from type-level singletons.
72- class KnownNat ( n :: Nat ) where
73- reifyNat :: proxy n -> Nat
70+ class KnownNat n where
71+ reifyNat :: proxy n -> Int
7472
75- instance KnownNat ' Z where
76- reifyNat _ = Z
73+ instance KnownNat Z where
74+ reifyNat _ = 0
7775
78- instance KnownNat n => KnownNat (' S n ) where
79- reifyNat _ = S ( reifyNat (undefined :: proxy n ) )
76+ instance KnownNat n => KnownNat (S n ) where
77+ reifyNat _ = 1 + reifyNat (undefined :: proxy n )
8078
8179
8280-- | Test the equality of type-level 'Nat's at runtime, generating a type-level equality if equal.
@@ -85,9 +83,9 @@ sameNat a b = unsafeCoerce Refl <$ guard (reifyNat a == reifyNat b)
8583
8684
8785-- FIXME: move this into its own module, or use a dependency, or something.
88- data Vec ( n :: Nat ) a where
89- Nil :: Vec ' Z a
90- Cons :: a -> Vec n a -> Vec (' S n ) a
86+ data Vec n a where
87+ Nil :: Vec Z a
88+ Cons :: a -> Vec n a -> Vec (S n ) a
9189
9290instance Eq a => Eq (Vec n a ) where
9391 Nil == Nil = True
0 commit comments