Skip to content

Commit 67ec770

Browse files
committed
cosmetics
1 parent ac1385f commit 67ec770

File tree

1 file changed

+21
-19
lines changed
  • chr-lang/src/CHR/Language/Examples/Term

1 file changed

+21
-19
lines changed

chr-lang/src/CHR/Language/Examples/Term/AST.hs

Lines changed: 21 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@ module CHR.Language.Examples.Term.AST
1313
, S', S
1414

1515
, Var
16+
17+
, TmEvalOp(..)
1618
)
1719
where
1820

@@ -129,13 +131,13 @@ instance PP tm => PP (G' tm) where
129131
pp (G_Ne x y) = "is-ne" >#< ppParensCommas [x,y]
130132
pp (G_Tm t ) = "eval" >#< ppParens t
131133

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
134136

135137
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
137139

138-
instance TT.TreeTrieKeyable Tm where
140+
instance TT.TreeTrieKeyable (Tm' op) where
139141
toTreeTriePreKey1 (Tm_Var v) = TT.prekey1Wild
140142
toTreeTriePreKey1 (Tm_Int i) = TT.prekey1 $ Key_Int i
141143
toTreeTriePreKey1 (Tm_Str s) = TT.prekey1 $ Key_Str {- $ "Tm_Str:" ++ -} s
@@ -144,7 +146,7 @@ instance TT.TreeTrieKeyable Tm where
144146
toTreeTriePreKey1 (Tm_Op op as) = TT.prekey1WithChildren (Key_Op op) as
145147
toTreeTriePreKey1 (Tm_Lst h _ ) = TT.prekey1WithChildren Key_Lst h
146148

147-
instance TT.TreeTrieKeyable C where
149+
instance (tm ~ Tm' op, TT.TrTrKey (C' tm) ~ TT.TrTrKey tm) => TT.TreeTrieKeyable (C' tm) where
148150
-- Only necessary for non-builtin constraints
149151
toTreeTriePreKey1 (C_Con c as) = TT.prekey1WithChildren (Key_Str {- $ "C_Con:" ++ -} c) as
150152
toTreeTriePreKey1 _ = TT.prekey1Nil
@@ -204,9 +206,9 @@ instance PP tm => PP (S' tm) where
204206
type instance ExtrValVarKey (G' tm) = Var
205207
type instance ExtrValVarKey (C' tm) = Var
206208
type instance ExtrValVarKey (Tm' op) = Var
207-
type instance ExtrValVarKey (P' op) = Var
209+
type instance ExtrValVarKey (P' tm) = Var
208210

209-
type instance CHRMatchableKey (S' (Tm' op)) = Key' op
211+
type instance CHRMatchableKey (S' (tm op)) = Key' op
210212

211213
instance VarLookup (S' tm) where
212214
varlookupWithMetaLev _ = Lk.lookup
@@ -374,19 +376,19 @@ instance GTermAs C G P P Tm where
374376

375377
asBodyConstraint t = case t of
376378
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
378381
a <- asTm a
379382
b <- asTm b
380-
return $ fromJust o' a b
381-
where o' = List.lookup o [("==", CB_Eq), ("/=", CB_Ne)]
383+
return $ o' a b
382384
t -> asHeadConstraint t
383385

384386
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
386389
a <- asTm a
387390
b <- asTm b
388-
return $ fromJust o' a b
389-
where o' = List.lookup o [("==", G_Eq), ("/=", G_Ne)]
391+
return $ o' a b
390392
t -> fmap G_Tm $ asTm t
391393

392394
asHeadBacktrackPrio = fmap P_Tm . asTm
@@ -397,15 +399,15 @@ instance GTermAs C G P P Tm where
397399
asTm t = case t of
398400
GTm_Con "True" [] -> return $ Tm_Bool True
399401
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
401404
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
405408
a <- asTm a
406409
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]
409411
GTm_Con c a -> forM a asTm >>= (return . Tm_Con c)
410412
GTm_Var v -> -- Tm_Var <$> gtermasVar v
411413
return $ Tm_Var v

0 commit comments

Comments
 (0)