Skip to content
This repository was archived by the owner on Apr 1, 2025. It is now read-only.

Commit f96b14d

Browse files
committed
Tone down the fancy.
1 parent be357c0 commit f96b14d

2 files changed

Lines changed: 19 additions & 21 deletions

File tree

semantic-analysis/src/Analysis/Syntax.hs

Lines changed: 18 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
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

9290
instance Eq a => Eq (Vec n a) where
9391
Nil == Nil = True

semantic-analysis/src/Analysis/Syntax/Python.hs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ import Source.Span (Span)
4343

4444
type Term = T.Term Python Name
4545

46-
data Python (arity :: T.Nat) where
46+
data Python arity where
4747
Noop' :: Python T.N0
4848
Iff' :: Python T.N3
4949
Bool' :: Bool -> Python T.N0

0 commit comments

Comments
 (0)