]> Git — Sourcephile - haskell/symantic.git/blob - symantic-grammar/Language/Symantic/Grammar/Source.hs
Rename source -> withSource, and g_*.
[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 'Inj_Source'
15 class Source src => Inj_Source a src where
16 inj_Source :: a -> src
17 instance Inj_Source a () where
18 inj_Source _ = ()
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 :: Inj_Source src (SourceOf a) => Sourced a => a -> src -> a
30 withSource a src = a `setSource` inj_Source 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)