]> Git — Sourcephile - haskell/symantic.git/blob - symantic-grammar/Language/Symantic/Grammar/Source.hs
Fix many and some.
[haskell/symantic.git] / symantic-grammar / Language / Symantic / Grammar / Source.hs
1 {-# LANGUAGE DeriveFunctor #-}
2 {-# LANGUAGE TypeFamilies #-}
3 module Language.Symantic.Grammar.Source where
4
5 import Data.Functor (Functor)
6 import Data.Typeable (Typeable)
7
8 -- * Class 'Source'
9 class Source src where
10 noSource :: src
11 instance Source () where
12 noSource = ()
13
14 -- ** Class 'SourceInj'
15 class Source src => SourceInj a src where
16 sourceInj :: a -> src
17 instance SourceInj a () where
18 sourceInj _ = ()
19
20 -- ** Type family 'SourceOf'
21 type family SourceOf a
22
23 -- ** Type 'Sourced'
24 class Source (SourceOf a) => Sourced a where
25 sourceOf :: a -> SourceOf a
26 setSource :: a -> SourceOf a -> a
27 infixl 5 `setSource`
28
29 withSource :: SourceInj src (SourceOf a) => Sourced a => a -> src -> a
30 withSource a src = a `setSource` sourceInj src
31
32 -- ** Type 'Source_Input'
33 type family Source_Input (src :: *) :: *
34 type instance Source_Input () = ()
35
36 -- ** Type 'Span'
37 data Span src
38 = Span
39 { spanBegin :: !src
40 , spanEnd :: !src
41 } deriving (Eq, Ord, Show, Typeable)
42
43 -- ** Type 'At'
44 -- | Attach a 'Source' to something.
45 data At src a
46 = At
47 { at :: !src
48 , unAt :: !a
49 } deriving (Eq, Functor, Ord, Show, Typeable)