Skip to content

Commit f0e60b3

Browse files
authored
Merge pull request #97 from statebox/83/refactor-3
Clean up Program.hs. #82
2 parents 3d70d13 + e46543b commit f0e60b3

File tree

1 file changed

+46
-46
lines changed

1 file changed

+46
-46
lines changed

src/Language/Program.hs

+46-46
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,57 @@
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+
#-}
46

57
module Language.Program where
68

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
1820

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
2628

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
3336
, transforms :: Ctx String t
34-
, other :: o
35-
}
37+
, other :: o
38+
}
3639

3740
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-
"\nschemas\n" ++ showCtx'' s ++
41-
"\ninstances\n" ++ showCtx'' i ++
42-
"\nmappings\n" ++ showCtx'' m ++
43-
"\nqueries\n" ++ showCtx'' q ++
44-
"\ntransforms\n" ++ showCtx'' t ++
45-
"\nother\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"
4649

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
4952

5053
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
5555

5656
--todo: store line numbers in other field
5757
type Prog = KindCtx TypesideExp SchemaExp InstanceExp MappingExp QueryExp TransformExp ([(String,Kind)])
@@ -60,13 +60,13 @@ type Types = KindCtx TypesideExp TypesideExp SchemaExp (SchemaExp,SchemaExp) (Sc
6060

6161
newProg :: KindCtx ts s i m q t [a]
6262
newProg = KindCtx m m m m m m []
63-
where m = Map.empty
63+
where m = Map.empty
6464

6565
newTypes :: KindCtx ts s i m q t ()
6666
newTypes = KindCtx m m m m m m ()
67-
where m = Map.empty
67+
where m = Map.empty
6868

6969

7070
newEnv :: KindCtx ts s i m q t ()
7171
newEnv = KindCtx m m m m m m ()
72-
where m = Map.empty
72+
where m = Map.empty

0 commit comments

Comments
 (0)