quox/lib/Quox/Name.idr

52 lines
855 B
Idris
Raw Normal View History

2021-07-20 16:05:19 -04:00
module Quox.Name
import public Data.SnocList
2022-05-06 18:57:23 -04:00
import Data.List
2022-05-13 01:05:55 -04:00
import Generics.Derive
%hide TT.Name
2021-07-20 16:05:19 -04:00
%default total
2022-05-13 01:05:55 -04:00
%language ElabReflection
2021-07-20 16:05:19 -04:00
public export
2022-05-13 01:05:55 -04:00
data BaseName
= UN String -- user-given name
%runElab derive "BaseName" [Generic, Meta, Eq, Ord, DecEq]
2021-07-20 16:05:19 -04:00
2022-05-06 18:57:23 -04:00
export
Show BaseName where
show (UN x) = x
2021-07-20 16:05:19 -04:00
export
baseStr : BaseName -> String
baseStr (UN x) = x
export
FromString BaseName where
fromString = UN
public export
record Name where
constructor MakeName
mods : SnocList String
base : BaseName
2022-05-13 01:05:55 -04:00
%runElab derive "Name" [Generic, Meta, Eq, Ord]
2021-07-20 16:05:19 -04:00
2022-05-06 18:57:23 -04:00
export
Show Name where
show (MakeName mods base) =
concat $ intersperse "." $ toList $ mods :< show base
2021-07-20 16:05:19 -04:00
export
FromString Name where
fromString x = MakeName [<] (fromString x)
export
toDots : Name -> String
toDots x = fastConcat $ cast $ map (<+> ".") x.mods :< baseStr x.base