summaryrefslogtreecommitdiff
path: root/src/CC/Name.idr
diff options
context:
space:
mode:
authorChloe Brown <chloe.brown.00@outlook.com>2023-03-26 03:50:28 +0100
committerChloe Brown <chloe.brown.00@outlook.com>2023-03-26 03:50:28 +0100
commit3649c9965e787c9cb0dc1cedc4400cdec4c5b8a2 (patch)
treebf1862fd4e3a6c3dd6117105a481ecc294f5a141 /src/CC/Name.idr
parent88ce0ee4ed72f75775da9c96668cad3e97554812 (diff)
Add type checking.HEADmaster
Currently, there is Set in Set. Next step is to add universe levels.
Diffstat (limited to 'src/CC/Name.idr')
-rw-r--r--src/CC/Name.idr25
1 files changed, 25 insertions, 0 deletions
diff --git a/src/CC/Name.idr b/src/CC/Name.idr
index 4c25f5c..d1df253 100644
--- a/src/CC/Name.idr
+++ b/src/CC/Name.idr
@@ -2,6 +2,10 @@ module CC.Name
import public Control.Relation
+import Data.List
+import Data.Singleton
+import Data.Stream
+
import Decidable.Equality
import Text.Bounded
@@ -65,3 +69,24 @@ decEquiv m n = decEq m.val n.val
export
bounds : (name : Name) -> Maybe Bounds
bounds name = if name.isIrrelevant then Nothing else Just name.bounds
+
+||| Returns a new name not in the set.
+export
+fresh : Foldable f => f Name -> Name
+fresh xs =
+ irrelevantBounds $
+ select (unfoldr (\n => ("_\{show n}", S n)) 0) $
+ sort $
+ foldMap (singleton . val) xs
+ where
+ select : Ord a => Stream a -> List a -> a
+ select (x :: xs) [] = x
+ select (x :: xs) (y :: ys) =
+ case compare x y of
+ LT => x
+ EQ => select xs ys
+ GT => select (x :: xs) ys
+
+export
+fresh' : Foldable f => Singleton {a = f Name} xs -> Name
+fresh' (Val xs) = fresh xs