on ca94170 help sign in
elk/compiler/src/Reporting/Annotation.hs
60 lines 896 B history raw
1{-# OPTIONS_GHC -Wall #-}
2module Reporting.Annotation
3 ( Located(..)
4 , at, merge
5 , map
6 , toValue
7 , toRegion
8 , traverse
9 )
10 where
13import Prelude hiding (map, traverse)
14import qualified Reporting.Region as R
18-- ANNOTATION
21data Located a =
22 At R.Region a
26-- CREATE
29at :: R.Position -> R.Position -> a -> Located a
30at start end value =
31 At (R.Region start end) value
34merge :: Located a -> Located b -> value -> Located value
35merge (At region1 _) (At region2 _) value =
36 At (R.merge region1 region2) value
40-- MANIPULATE
43map :: (a -> b) -> Located a -> Located b
44map f (At info value) =
45 At info (f value)
48toValue :: Located a -> a
49toValue (At _ value) =
50 value
53toRegion :: Located a -> R.Region
54toRegion (At region _) =
55 region
58traverse :: (Functor f) => (a -> f b) -> Located a -> f (Located b)
59traverse func (At region value) =
60 At region <$> func value