diff options
author | Péter Diviánszky <divipp@gmail.com> | 2015-10-04 15:36:06 +0200 |
---|---|---|
committer | Péter Diviánszky <divipp@gmail.com> | 2015-10-04 15:36:06 +0200 |
commit | 80a1a9980a8eefa0948583585fe7e6332687f45d (patch) | |
tree | c26ce703bc6c8025d06bac2d391d4f4d15f26345 /prototypes/TCReduce.hs | |
parent | ed5d80e95eb578fe906f070efeb4f69c26ace959 (diff) |
refactoring: move closer to Bound
Diffstat (limited to 'prototypes/TCReduce.hs')
-rw-r--r-- | prototypes/TCReduce.hs | 58 |
1 files changed, 37 insertions, 21 deletions
diff --git a/prototypes/TCReduce.hs b/prototypes/TCReduce.hs index e74b58e0..ed292273 100644 --- a/prototypes/TCReduce.hs +++ b/prototypes/TCReduce.hs | |||
@@ -40,30 +40,38 @@ import Unsafe.Coerce | |||
40 | -} | 40 | -} |
41 | -------------------------------------------------------------------------------- | 41 | -------------------------------------------------------------------------------- |
42 | 42 | ||
43 | data CTerm | 43 | data CTerm_ t |
44 | = Inf ITerm | 44 | = Inf (ITerm_ t) |
45 | | Lam CTerm | 45 | | Lam (CTerm_ t) |
46 | deriving (Show, Eq) | 46 | deriving (Eq, Show) |
47 | |||
48 | type CTerm = CTerm_ Var | ||
49 | type ITerm = ITerm_ Var | ||
47 | 50 | ||
48 | type ITerm = ITerm_ CTerm | 51 | data Var |
52 | = Bound_ !Int | ||
53 | | Global_ String | ||
54 | deriving (Eq, Ord, Show) | ||
55 | |||
56 | pattern Bound a = Var (Bound_ a) | ||
57 | pattern Global a = Var (Global_ a) | ||
49 | 58 | ||
50 | data ITerm_ t | 59 | data ITerm_ t |
51 | = Ann t t | 60 | = Ann (CTerm_ t) (CTerm_ t) |
52 | | Star | 61 | | Star |
53 | | Pi Relevance t t | 62 | | Pi Relevance (CTerm_ t) (CTerm_ t) |
54 | | Bound !Int | 63 | | Var t |
55 | | Global String | ||
56 | 64 | ||
57 | | CCon CConName [t] [t] | 65 | | CCon CConName [CTerm_ t] [CTerm_ t] |
58 | | ITCon TConName [t] | 66 | | ITCon TConName [CTerm_ t] |
59 | | IInt !Int | 67 | | IInt !Int |
60 | 68 | ||
61 | -- neutral | 69 | -- neutral |
62 | | ITerm_ t :$: t | 70 | | ITerm_ t :$: CTerm_ t |
63 | 71 | ||
64 | | ICase TConName [t] t [t] [t] t | 72 | | ICase TConName [CTerm_ t] (CTerm_ t) [CTerm_ t] [CTerm_ t] (CTerm_ t) |
65 | | Prim PrimName' [t] | 73 | | Prim PrimName' [CTerm_ t] |
66 | deriving (Show, Functor) | 74 | deriving (Eq, Show) -- , Functor) |
67 | 75 | ||
68 | data Value_ f t | 76 | data Value_ f t |
69 | -- real values | 77 | -- real values |
@@ -79,7 +87,7 @@ data Value_ f t | |||
79 | -- neutral values | 87 | -- neutral values |
80 | | VNeutral_ (Neutral_ t) | 88 | | VNeutral_ (Neutral_ t) |
81 | | VTag_ (Neutral_ t) t -- todo: eliminate | 89 | | VTag_ (Neutral_ t) t -- todo: eliminate |
82 | deriving Functor | 90 | -- deriving Functor |
83 | 91 | ||
84 | type Neutral = Neutral_ Value | 92 | type Neutral = Neutral_ Value |
85 | data Neutral_ t | 93 | data Neutral_ t |
@@ -89,7 +97,7 @@ data Neutral_ t | |||
89 | 97 | ||
90 | | NCase t [t] (Neutral_ t) | 98 | | NCase t [t] (Neutral_ t) |
91 | | NPrim PrimName' [t] | 99 | | NPrim PrimName' [t] |
92 | deriving Functor | 100 | -- deriving Functor |
93 | 101 | ||
94 | newtype Value = V {unV :: Value_ ((->) Value) Value} | 102 | newtype Value = V {unV :: Value_ ((->) Value) Value} |
95 | 103 | ||
@@ -132,12 +140,12 @@ pattern VInt a = V (VInt_ a) | |||
132 | 140 | ||
133 | instance Show Value where | 141 | instance Show Value where |
134 | show = show . quote0 tInt -- (error "show value") | 142 | show = show . quote0 tInt -- (error "show value") |
135 | 143 | {- | |
136 | instance Eq t => Eq (ITerm_ t) where | 144 | instance Eq ITerm where |
137 | Star == Star = True | 145 | Star == Star = True |
138 | Bound i == Bound j = i == j | 146 | Bound i == Bound j = i == j |
139 | _ == _ = False -- TODO | 147 | _ == _ = False -- TODO |
140 | 148 | -} | |
141 | instance Show CConName where show (CConName _ s _ _) = s | 149 | instance Show CConName where show (CConName _ s _ _) = s |
142 | instance Eq CConName where CConName i _ _ _ == CConName j _ _ _ = i == j | 150 | instance Eq CConName where CConName i _ _ _ == CConName j _ _ _ = i == j |
143 | 151 | ||
@@ -226,7 +234,15 @@ chain q ps end = f [] ps where | |||
226 | iSubst f ii (Pi r ty ty') = Pi r (cSubst' f ii ty) (cSubst' f (ii + 1) ty') | 234 | iSubst f ii (Pi r ty ty') = Pi r (cSubst' f ii ty) (cSubst' f (ii + 1) ty') |
227 | iSubst f ii (Bound j) = f ii j | 235 | iSubst f ii (Bound j) = f ii j |
228 | iSubst f ii (i :$: c) = iSubst f ii i :$: cSubst' f ii c | 236 | iSubst f ii (i :$: c) = iSubst f ii i :$: cSubst' f ii c |
229 | iSubst f ii x = cSubst' f ii <$> x | 237 | iSubst f ii x = case x of |
238 | Ann a b -> Ann (g a) (g b) | ||
239 | CCon con a b -> CCon con (g <$> a) (g <$> b) | ||
240 | ITCon con a -> ITCon con (g <$> a) | ||
241 | Prim con a -> Prim con (g <$> a) | ||
242 | ICase con a b c d e -> ICase con (g <$> a) (g b) (g <$> c) (g <$> d) (g e) | ||
243 | x -> x | ||
244 | where | ||
245 | g = cSubst' f ii | ||
230 | 246 | ||
231 | --cSubst' :: Int -> ITerm -> CTerm -> CTerm | 247 | --cSubst' :: Int -> ITerm -> CTerm -> CTerm |
232 | cSubst' f ii (Inf i) = Inf (iSubst f ii i) | 248 | cSubst' f ii (Inf i) = Inf (iSubst f ii i) |