15 | showPrec d (MkBounds sl sc el ec) =
16 | showCon d "MkBounds" (concat [showArg sl, showArg sc, showArg el, showArg ec])
19 | startBounds : Bounds -> (Int, Int)
20 | startBounds b = (b.startLine, b.startCol)
23 | endBounds : Bounds -> (Int, Int)
24 | endBounds b = (b.endLine, b.endCol)
28 | (MkBounds sl sc el ec) == (MkBounds sl' sc' el' ec') =
35 | record WithBounds ty where
36 | constructor MkBounded
42 | start : WithBounds ty -> (Int, Int)
43 | start = startBounds . bounds
46 | end : WithBounds ty -> (Int, Int)
47 | end = endBounds . bounds
50 | Eq ty => Eq (WithBounds ty) where
51 | (MkBounded val ir bd) == (MkBounded val' ir' bd') =
52 | val == val' && ir == ir' && bd == bd'
55 | Show ty => Show (WithBounds ty) where
56 | showPrec d (MkBounded val ir bd) =
57 | showCon d "MkBounded" (concat [showArg ir, showArg val, showArg bd])
60 | Functor WithBounds where
61 | map f (MkBounded val ir bd) = MkBounded (f val) ir bd
64 | Foldable WithBounds where
65 | foldr c n b = c b.val n
68 | Traversable WithBounds where
69 | traverse f (MkBounded v a bd) = (\ v => MkBounded v a bd) <$> f v
72 | irrelevantBounds : ty -> WithBounds ty
73 | irrelevantBounds x = MkBounded x True (MkBounds (-
1) (-
1) (-
1) (-
1))
76 | removeIrrelevance : WithBounds ty -> WithBounds ty
77 | removeIrrelevance (MkBounded val ir bd) = MkBounded val True bd
80 | mergeBounds : WithBounds ty -> WithBounds ty' -> WithBounds ty'
81 | mergeBounds (MkBounded _ True _) (MkBounded val True _) = irrelevantBounds val
82 | mergeBounds (MkBounded _ True _) b2 = b2
83 | mergeBounds b1 (MkBounded val True _) = const val <$> b1
85 | let (ur, uc) = min (start b1) (start b2)
86 | (lr, lc) = max (end b1) (end b2) in
87 | MkBounded b2.val False (MkBounds ur uc lr lc)
90 | joinBounds : WithBounds (WithBounds ty) -> WithBounds ty
91 | joinBounds b = mergeBounds b b.val