Use instances to simplify printing code

Signed-off-by: Danila Fedorin <danila.fedorin@gmail.com>
This commit is contained in:
2024-03-11 12:50:05 -07:00
parent 56da61b339
commit 040c13caba
5 changed files with 78 additions and 15 deletions

View File

@@ -13,6 +13,7 @@ open import Function using (_∘_)
open import Language
open import Lattice
open import Utils using (Pairwise)
open import Showable using (Showable; show)
import Lattice.FiniteValueMap
data Sign : Set where
@@ -20,6 +21,16 @@ data Sign : Set where
- : Sign
0ˢ : Sign
instance
showable : Showable Sign
showable = record
{ show = (λ
{ + → "+"
; - → "-"
; 0ˢ → "0"
})
}
-- g for siGn; s is used for strings and i is not very descriptive.
_≟ᵍ_ : IsDecidable (_≡_ {_} {Sign})
_≟ᵍ_ + + = yes refl
@@ -301,20 +312,7 @@ module WithProg (prog : Program) where
open import Data.String using (_++_)
open import Data.List using () renaming (length to lengthˡ)
showAboveBelow : AB.AboveBelow → String
showAboveBelow AB.⊤ = "⊤"
showAboveBelow AB.⊥ = "⊥"
showAboveBelow (AB.[_] +) = "+"
showAboveBelow (AB.[_] -) = "-"
showAboveBelow (AB.[_] 0ˢ) = "0"
showVarSigns : VariableSigns → String
showVarSigns ((kvs , _) , _) = "{" ++ foldr (λ (x , y) rest → x ++ " ↦ " ++ showAboveBelow y ++ ", " ++ rest) "" kvs ++ "}"
showStateVars : StateVariables → String
showStateVars ((kvs , _) , _) = "{" ++ foldr (λ (x , y) rest → (showFin x) ++ " ↦ " ++ showVarSigns y ++ ", " ++ rest) "" kvs ++ "}"
output = showStateVars signs
output = show signs
-- Debugging code: construct and run a program.