1
-
2
- {-# LANGUAGE ExplicitForAll, StandaloneDeriving, DuplicateRecordFields, ScopedTypeVariables, InstanceSigs, KindSignatures, GADTs, FlexibleContexts, RankNTypes, TypeSynonymInstances, FlexibleInstances, MultiParamTypeClasses, AllowAmbiguousTypes, TypeOperators
3
- ,LiberalTypeSynonyms, ImpredicativeTypes, UndecidableInstances, FunctionalDependencies #-}
1
+ {-# LANGUAGE ExplicitForAll, StandaloneDeriving, DuplicateRecordFields, ScopedTypeVariables, InstanceSigs
2
+ , KindSignatures, GADTs, FlexibleContexts, RankNTypes, TypeSynonymInstances, FlexibleInstances
3
+ , MultiParamTypeClasses, AllowAmbiguousTypes, TypeOperators, LiberalTypeSynonyms, ImpredicativeTypes
4
+ , UndecidableInstances, FunctionalDependencies
5
+ #-}
4
6
5
7
module Language.Program where
6
8
7
- import Prelude hiding (EQ )
8
- import Data.Map.Strict as Map
9
- import Language.Common as C
10
- import Language.Term as Term
11
- import Language.Schema as S
12
- import Language.Instance as I
13
- import Language.Mapping as M
14
- import Language.Typeside as T
15
- import Language.Transform as Tr
16
- import Language.Query as Q
17
-
9
+ import Prelude hiding (EQ )
10
+ import Data.Maybe ( fromMaybe )
11
+ import Data.Map.Strict as Map
12
+ import Language.Common as C
13
+ import Language.Instance as I
14
+ import Language.Mapping as M
15
+ import Language.Schema as S
16
+ import Language.Term as Term
17
+ import Language.Query as Q
18
+ import Language.Transform as Tr
19
+ import Language.Typeside as T
18
20
19
- data Exp =
20
- ExpTy ( TypesideExp )
21
- | ExpS ( SchemaExp )
22
- | ExpI ( InstanceExp )
23
- | ExpM ( MappingExp )
24
- | ExpT ( TransformExp )
25
- | ExpQ ( QueryExp )
21
+ data Exp
22
+ = ExpTy TypesideExp
23
+ | ExpS SchemaExp
24
+ | ExpI InstanceExp
25
+ | ExpM MappingExp
26
+ | ExpT TransformExp
27
+ | ExpQ QueryExp
26
28
27
- data KindCtx ts s i m q t o = KindCtx {
28
- typesides :: Ctx String ts
29
- , schemas :: Ctx String s
30
- , instances :: Ctx String i
31
- , mappings :: Ctx String m
32
- , queries :: Ctx String q
29
+ data KindCtx ts s i m q t o
30
+ = KindCtx
31
+ { typesides :: Ctx String ts
32
+ , schemas :: Ctx String s
33
+ , instances :: Ctx String i
34
+ , mappings :: Ctx String m
35
+ , queries :: Ctx String q
33
36
, transforms :: Ctx String t
34
- , other :: o
35
- }
37
+ , other :: o
38
+ }
36
39
37
40
instance (Show ts , Show s , Show i , Show m , Show q , Show t , Show o ) => Show (KindCtx ts s i m q t o ) where
38
- show (KindCtx ts s i m q t o) =
39
- " typesides\n " ++ showCtx'' ts ++
40
- " \n schemas \ n" ++ showCtx'' s ++
41
- " \n instances \ n" ++ showCtx'' i ++
42
- " \n mappings \ n" ++ showCtx'' m ++
43
- " \n queries \ n" ++ showCtx'' q ++
44
- " \n transforms \ n" ++ showCtx'' t ++
45
- " \n other \ n" ++ show o ++ " \n "
41
+ show (KindCtx ts s i m q t o) =
42
+ " typesides\n " ++ showCtx'' ts ++ " \n " ++
43
+ " schemas \ n" ++ showCtx'' s ++ " \n " ++
44
+ " instances \ n" ++ showCtx'' i ++ " \n " ++
45
+ " mappings \ n" ++ showCtx'' m ++ " \n " ++
46
+ " queries \ n" ++ showCtx'' q ++ " \n " ++
47
+ " transforms \ n" ++ showCtx'' t ++ " \n " ++
48
+ " other \ n" ++ show o ++ " \n "
46
49
47
- showCtx'' :: (Show a1 , Show a2 ) => Map a1 a2 -> [ Char ]
48
- showCtx'' m = intercalate " \n " $ Prelude. map (\ (k,v) -> show k ++ " = " ++ show v ++ " \n " ) $ Map. toList m
50
+ showCtx'' :: (Show a1 , Show a2 ) => Map a1 a2 -> String
51
+ showCtx'' m = intercalate " \n " $ (\ (k,v) -> show k ++ " = " ++ show v ++ " \n " ) <$> Map. toList m
49
52
50
53
lookup' :: (Show k , Show a , Ord k ) => k -> Map k a -> a
51
- lookup' m v = f $ Map. lookup m v
52
- where
53
- f (Just x) = x
54
- f Nothing = error $ " Can't find " ++ show v ++ " in " ++ show m
54
+ lookup' m v = fromMaybe (error $ " Can't find " ++ show v ++ " in " ++ show m) $ Map. lookup m v
55
55
56
56
-- todo: store line numbers in other field
57
57
type Prog = KindCtx TypesideExp SchemaExp InstanceExp MappingExp QueryExp TransformExp ([(String ,Kind )])
@@ -60,13 +60,13 @@ type Types = KindCtx TypesideExp TypesideExp SchemaExp (SchemaExp,SchemaExp) (Sc
60
60
61
61
newProg :: KindCtx ts s i m q t [a ]
62
62
newProg = KindCtx m m m m m m []
63
- where m = Map. empty
63
+ where m = Map. empty
64
64
65
65
newTypes :: KindCtx ts s i m q t ()
66
66
newTypes = KindCtx m m m m m m ()
67
- where m = Map. empty
67
+ where m = Map. empty
68
68
69
69
70
70
newEnv :: KindCtx ts s i m q t ()
71
71
newEnv = KindCtx m m m m m m ()
72
- where m = Map. empty
72
+ where m = Map. empty
0 commit comments