Show for Name and Dim

This commit is contained in:
rhiannon morris 2022-05-07 00:57:23 +02:00
parent 804f1e3638
commit 715a9fe8f9
2 changed files with 16 additions and 0 deletions

View file

@ -1,6 +1,7 @@
module Quox.Name module Quox.Name
import public Data.SnocList import public Data.SnocList
import Data.List
%default total %default total
@ -18,6 +19,11 @@ brepr (UN x) = x
export Eq BaseName where (==) = (==) `on` brepr export Eq BaseName where (==) = (==) `on` brepr
export Ord BaseName where compare = compare `on` brepr export Ord BaseName where compare = compare `on` brepr
export
Show BaseName where
show (UN x) = x
export export
baseStr : BaseName -> String baseStr : BaseName -> String
baseStr (UN x) = x baseStr (UN x) = x
@ -42,6 +48,11 @@ repr x = (x.mods, brepr x.base)
export Eq Name where (==) = (==) `on` repr export Eq Name where (==) = (==) `on` repr
export Ord Name where compare = compare `on` repr export Ord Name where compare = compare `on` repr
export
Show Name where
show (MakeName mods base) =
concat $ intersperse "." $ toList $ mods :< show base
export export
FromString Name where FromString Name where
fromString x = MakeName [<] (fromString x) fromString x = MakeName [<] (fromString x)

View file

@ -37,6 +37,11 @@ drepr (B x) = Right x
export Eq (Dim n) where (==) = (==) `on` drepr export Eq (Dim n) where (==) = (==) `on` drepr
export Ord (Dim n) where compare = compare `on` drepr export Ord (Dim n) where compare = compare `on` drepr
export
Show (Dim n) where
show (K k) = showCon App "K" $ show k
show (B i) = showCon App "B" $ show i
export export
PrettyHL DimConst where PrettyHL DimConst where
prettyM Zero = hl Dim <$> ifUnicode "𝟬" "0" prettyM Zero = hl Dim <$> ifUnicode "𝟬" "0"