@@ -13,6 +13,8 @@ module CHR.Language.Examples.Term.AST
13
13
, S' , S
14
14
15
15
, Var
16
+
17
+ , TmEvalOp (.. )
16
18
)
17
19
where
18
20
@@ -129,13 +131,13 @@ instance PP tm => PP (G' tm) where
129
131
pp (G_Ne x y) = " is-ne" >#< ppParensCommas [x,y]
130
132
pp (G_Tm t ) = " eval" >#< ppParens t
131
133
132
- type instance TrTrKey (Tm' op ) = Key' op
133
- type instance TrTrKey (C' (Tm' op )) = Key' op
134
+ -- type instance TrTrKey (Tm' op) = Key' op
135
+ -- type instance TrTrKey (C' (Tm' op)) = Key' op
134
136
135
137
type instance TT. TrTrKey (Tm' op ) = Key' op
136
- type instance TT. TrTrKey (C' (Tm' op )) = Key' op
138
+ type instance TT. TrTrKey (C' (tm op )) = Key' op
137
139
138
- instance TT. TreeTrieKeyable Tm where
140
+ instance TT. TreeTrieKeyable ( Tm' op ) where
139
141
toTreeTriePreKey1 (Tm_Var v) = TT. prekey1Wild
140
142
toTreeTriePreKey1 (Tm_Int i) = TT. prekey1 $ Key_Int i
141
143
toTreeTriePreKey1 (Tm_Str s) = TT. prekey1 $ Key_Str {- $ "Tm_Str:" ++ -} s
@@ -144,7 +146,7 @@ instance TT.TreeTrieKeyable Tm where
144
146
toTreeTriePreKey1 (Tm_Op op as) = TT. prekey1WithChildren (Key_Op op) as
145
147
toTreeTriePreKey1 (Tm_Lst h _ ) = TT. prekey1WithChildren Key_Lst h
146
148
147
- instance TT. TreeTrieKeyable C where
149
+ instance ( tm ~ Tm' op , TT. TrTrKey ( C' tm ) ~ TT. TrTrKey tm ) => TT. TreeTrieKeyable ( C' tm ) where
148
150
-- Only necessary for non-builtin constraints
149
151
toTreeTriePreKey1 (C_Con c as) = TT. prekey1WithChildren (Key_Str {- $ "C_Con:" ++ -} c) as
150
152
toTreeTriePreKey1 _ = TT. prekey1Nil
@@ -204,9 +206,9 @@ instance PP tm => PP (S' tm) where
204
206
type instance ExtrValVarKey (G' tm ) = Var
205
207
type instance ExtrValVarKey (C' tm ) = Var
206
208
type instance ExtrValVarKey (Tm' op ) = Var
207
- type instance ExtrValVarKey (P' op ) = Var
209
+ type instance ExtrValVarKey (P' tm ) = Var
208
210
209
- type instance CHRMatchableKey (S' (Tm' op )) = Key' op
211
+ type instance CHRMatchableKey (S' (tm op )) = Key' op
210
212
211
213
instance VarLookup (S' tm ) where
212
214
varlookupWithMetaLev _ = Lk. lookup
@@ -374,19 +376,19 @@ instance GTermAs C G P P Tm where
374
376
375
377
asBodyConstraint t = case t of
376
378
GTm_Con " Fail" [] -> return CB_Fail
377
- GTm_Con o [a,b] | isJust o' -> do
379
+ GTm_Con o [a,b]
380
+ | Just o' <- List. lookup o [(" ==" , CB_Eq ), (" /=" , CB_Ne )] -> do
378
381
a <- asTm a
379
382
b <- asTm b
380
- return $ fromJust o' a b
381
- where o' = List. lookup o [(" ==" , CB_Eq ), (" /=" , CB_Ne )]
383
+ return $ o' a b
382
384
t -> asHeadConstraint t
383
385
384
386
asGuard t = case t of
385
- GTm_Con o [a,b] | isJust o' -> do
387
+ GTm_Con o [a,b]
388
+ | Just o' <- List. lookup o [(" ==" , G_Eq ), (" /=" , G_Ne )] -> do
386
389
a <- asTm a
387
390
b <- asTm b
388
- return $ fromJust o' a b
389
- where o' = List. lookup o [(" ==" , G_Eq ), (" /=" , G_Ne )]
391
+ return $ o' a b
390
392
t -> fmap G_Tm $ asTm t
391
393
392
394
asHeadBacktrackPrio = fmap P_Tm . asTm
@@ -397,15 +399,15 @@ instance GTermAs C G P P Tm where
397
399
asTm t = case t of
398
400
GTm_Con " True" [] -> return $ Tm_Bool True
399
401
GTm_Con " False" [] -> return $ Tm_Bool False
400
- GTm_Con o [a] | isJust o' -> do
402
+ GTm_Con o [a]
403
+ | Just o' <- List. lookup o [(" Abs" , PUOp_Abs )] -> do
401
404
a <- asTm a
402
- return $ Tm_Op (fromJust o') [a]
403
- where o' = List. lookup o [( " Abs " , PUOp_Abs ) ]
404
- GTm_Con o [a,b] | isJust o' -> do
405
+ return $ Tm_Op o' [a]
406
+ GTm_Con o [a,b ]
407
+ | Just o' <- List. lookup o [( " + " , PBOp_Add ), ( " - " , PBOp_Sub ), ( " * " , PBOp_Mul ), ( " Mod " , PBOp_Mod ), ( " < " , PBOp_Lt ), ( " <= " , PBOp_Le )] -> do
405
408
a <- asTm a
406
409
b <- asTm b
407
- return $ Tm_Op (fromJust o') [a,b]
408
- where o' = List. lookup o [(" +" , PBOp_Add ), (" -" , PBOp_Sub ), (" *" , PBOp_Mul ), (" Mod" , PBOp_Mod ), (" <" , PBOp_Lt ), (" <=" , PBOp_Le )]
410
+ return $ Tm_Op o' [a,b]
409
411
GTm_Con c a -> forM a asTm >>= (return . Tm_Con c)
410
412
GTm_Var v -> -- Tm_Var <$> gtermasVar v
411
413
return $ Tm_Var v
0 commit comments