on master help sign in
Switch all of the AST modules from String to Text
c0b4375Evan Czaplicki
src/AST/Expression/Canonical.hs+14−12
@@ -1,4 +1,5 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2+{-# LANGUAGE OverloadedStrings #-}
2module AST.Expression.Canonical
3module AST.Expression.Canonical
3 ( Expr, Expr'(..)
4 ( Expr, Expr'(..)
4 , Main(..)
5 , Main(..)
@@ -10,7 +11,8 @@ module AST.Expression.Canonical
10 where
11 where
11
12
12
13
13−import qualified Data.List as List
14+import qualified Data.Text as Text
15+import Data.Text (Text)
14
16
15import qualified AST.Effects as Effects
17import qualified AST.Effects as Effects
16import qualified AST.Literal as Literal
18import qualified AST.Literal as Literal
@@ -40,18 +42,18 @@ data Expr'
40 | If [(Expr, Expr)] Expr
42 | If [(Expr, Expr)] Expr
41 | Let [Def] Expr
43 | Let [Def] Expr
42 | Case Expr [(Ptrn.Canonical, Expr)]
44 | Case Expr [(Ptrn.Canonical, Expr)]
43− | Ctor String [Expr]
45+ | Ctor Text [Expr]
44− | Access Expr String
46+ | Access Expr Text
45− | Update Expr [(String, Expr)]
47+ | Update Expr [(Text, Expr)]
46− | Record [(String, Expr)]
48+ | Record [(Text, Expr)]
47 -- for type checking and code gen only
49 -- for type checking and code gen only
48 | Cmd ModuleName.Canonical
50 | Cmd ModuleName.Canonical
49 | Sub ModuleName.Canonical
51 | Sub ModuleName.Canonical
50− | OutgoingPort String Type.Canonical
52+ | OutgoingPort Text Type.Canonical
51− | IncomingPort String Type.Canonical
53+ | IncomingPort Text Type.Canonical
52 | Program Main Expr
54 | Program Main Expr
53 | SaveEnv ModuleName.Canonical Effects.Canonical
55 | SaveEnv ModuleName.Canonical Effects.Canonical
54− | GLShader String String Literal.GLShaderTipe
56+ | GLShader Text Text Literal.GLShaderTipe
55
57
56
58
57data Main
59data Main
@@ -109,7 +111,7 @@ defCons def@(Def _ (A.A _ pattern) _ _) sortedDefs =
109-- HELPERS
111-- HELPERS
110
112
111
113
112−localVar :: String -> Expr'
114+localVar :: Text -> Expr'
113localVar x =
115localVar x =
114 Var (Var.Canonical Var.Local x)
116 Var (Var.Canonical Var.Local x)
115
117
@@ -128,16 +130,16 @@ collectApps annExpr@(A.A _ expr) =
128
130
129
131
130
132
131−collectFields :: Expr -> Maybe String
133+collectFields :: Expr -> Maybe Text
132collectFields expr =
134collectFields expr =
133 collectFieldsHelp expr []
135 collectFieldsHelp expr []
134
136
135
137
136−collectFieldsHelp :: Expr -> [String] -> Maybe String
138+collectFieldsHelp :: Expr -> [Text] -> Maybe Text
137collectFieldsHelp (A.A _ expr) fields =
139collectFieldsHelp (A.A _ expr) fields =
138 case expr of
140 case expr of
139 Var var ->
141 Var var ->
140− Just (List.intercalate "." (Var.toString var : fields))
142+ Just (Text.intercalate "." (Text.pack (Var.toString var) : fields))
141
143
142 Access record field ->
144 Access record field ->
143 collectFieldsHelp record (field : fields)
145 collectFieldsHelp record (field : fields)
src/AST/Expression/Optimized.hs+14−12
@@ -5,6 +5,8 @@ module AST.Expression.Optimized
5 , Decider(..), Choice(..)
5 , Decider(..), Choice(..)
6 ) where
6 ) where
7
7
8+import Data.Text (Text)
9+
8import qualified AST.Expression.Canonical as Can
10import qualified AST.Expression.Canonical as Can
9import qualified AST.Literal as Literal
11import qualified AST.Literal as Literal
10import qualified AST.Module.Name as ModuleName
12import qualified AST.Module.Name as ModuleName
@@ -18,8 +20,8 @@ import qualified Reporting.Region as R
18-- DEFINITIONS
20-- DEFINITIONS
19
21
20data Def
22data Def
21− = Def Facts String Expr
23+ = Def Facts Text Expr
22− | TailDef Facts String [String] Expr
24+ | TailDef Facts Text [Text] Expr
23
25
24
26
25data Facts = Facts
27data Facts = Facts
@@ -39,23 +41,23 @@ data Expr
39 | Var Var.Canonical
41 | Var Var.Canonical
40 | List [Expr]
42 | List [Expr]
41 | Binop Var.Canonical Expr Expr
43 | Binop Var.Canonical Expr Expr
42− | Function [String] Expr
44+ | Function [Text] Expr
43 | Call Expr [Expr]
45 | Call Expr [Expr]
44− | TailCall String [String] [Expr]
46+ | TailCall Text [Text] [Expr]
45 | If [(Expr, Expr)] Expr
47 | If [(Expr, Expr)] Expr
46 | Let [Def] Expr
48 | Let [Def] Expr
47− | Case String (Decider Choice) [(Int, Expr)]
49+ | Case Text (Decider Choice) [(Int, Expr)]
48− | Ctor String [Expr]
50+ | Ctor Text [Expr]
49 | CtorAccess Expr Int
51 | CtorAccess Expr Int
50− | Access Expr String
52+ | Access Expr Text
51− | Update Expr [(String, Expr)]
53+ | Update Expr [(Text, Expr)]
52− | Record [(String, Expr)]
54+ | Record [(Text, Expr)]
53 | Cmd ModuleName.Canonical
55 | Cmd ModuleName.Canonical
54 | Sub ModuleName.Canonical
56 | Sub ModuleName.Canonical
55− | OutgoingPort String Type.Canonical
57+ | OutgoingPort Text Type.Canonical
56− | IncomingPort String Type.Canonical
58+ | IncomingPort Text Type.Canonical
57 | Program Can.Main Expr
59 | Program Can.Main Expr
58− | GLShader String String Literal.GLShaderTipe
60+ | GLShader Text Text Literal.GLShaderTipe
59 | Crash ModuleName.Canonical R.Region (Maybe Expr)
61 | Crash ModuleName.Canonical R.Region (Maybe Expr)
60
62
61
63
src/AST/Expression/Source.hs+17−10
@@ -3,10 +3,12 @@ module AST.Expression.Source
3 ( RawExpr, RawExpr', RawDef, RawDef'(..)
3 ( RawExpr, RawExpr', RawDef, RawDef'(..)
4 , ValidExpr, ValidExpr', ValidDef(..)
4 , ValidExpr, ValidExpr', ValidDef(..)
5 , Expr, Expr'(..)
5 , Expr, Expr'(..)
6− , var, tuple, getPattern, collectLambdas
6+ , var, tuple, zero, getPattern, collectLambdas
7 )
7 )
8 where
8 where
9
9
10+import qualified Data.Text as Text
11+import Data.Text (Text)
10
12
11import qualified AST.Literal as Literal
13import qualified AST.Literal as Literal
12import qualified AST.Pattern as Ptrn
14import qualified AST.Pattern as Ptrn
@@ -28,17 +30,17 @@ data Expr' def
28 = Literal Literal.Literal
30 = Literal Literal.Literal
29 | Var Var.Raw
31 | Var Var.Raw
30 | List [Expr def]
32 | List [Expr def]
31− | Binop [(Expr def, A.Located String)] (Expr def)
33+ | Binop [(Expr def, A.Located Text)] (Expr def)
32 | Lambda Ptrn.Raw (Expr def)
34 | Lambda Ptrn.Raw (Expr def)
33 | App (Expr def) (Expr def)
35 | App (Expr def) (Expr def)
34 | If [(Expr def, Expr def)] (Expr def)
36 | If [(Expr def, Expr def)] (Expr def)
35 | Let [def] (Expr def)
37 | Let [def] (Expr def)
36 | Case (Expr def) [(Ptrn.Raw, Expr def)]
38 | Case (Expr def) [(Ptrn.Raw, Expr def)]
37− | Ctor String [Expr def]
39+ | Ctor Text [Expr def]
38− | Access (Expr def) String
40+ | Access (Expr def) Text
39− | Update (Expr def) [(A.Located String, Expr def)]
41+ | Update (Expr def) [(A.Located Text, Expr def)]
40− | Record [(A.Located String, Expr def)]
42+ | Record [(A.Located Text, Expr def)]
41− | GLShader String String Literal.GLShaderTipe
43+ | GLShader Text Text Literal.GLShaderTipe
42
44
43
45
44type RawExpr = Expr RawDef
46type RawExpr = Expr RawDef
@@ -60,7 +62,7 @@ type RawDef =
60
62
61data RawDef'
63data RawDef'
62 = Definition Ptrn.Raw RawExpr
64 = Definition Ptrn.Raw RawExpr
63− | Annotation String Type.Raw
65+ | Annotation Text Type.Raw
64
66
65
67
66data ValidDef =
68data ValidDef =
@@ -71,14 +73,19 @@ data ValidDef =
71-- HELPERS
73-- HELPERS
72
74
73
75
74−var :: String -> Expr' def
76+var :: Text -> Expr' def
75var x =
77var x =
76 Var (Var.Raw x)
78 Var (Var.Raw x)
77
79
78
80
79tuple :: [Expr def] -> Expr' def
81tuple :: [Expr def] -> Expr' def
80tuple expressions =
82tuple expressions =
81− Ctor ("_Tuple" ++ show (length expressions)) expressions
83+ Ctor (Text.pack ("_Tuple" ++ show (length expressions))) expressions
84+
85+
86+zero :: Expr' def
87+zero =
88+ Literal (Literal.IntNum 0)
82
89
83
90
84getPattern :: ValidDef -> Ptrn.Raw
91getPattern :: ValidDef -> Ptrn.Raw
src/AST/Helpers.hs+15−15
@@ -1,32 +1,32 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2+{-# LANGUAGE OverloadedStrings #-}
2module AST.Helpers where
3module AST.Helpers where
3
4
4import qualified Data.Char as Char
5import qualified Data.Char as Char
6+import qualified Data.Text as Text
7+import Data.Text (Text)
5
8
6
9
7
10
8−splitDots :: String -> [String]
11+-- TUPLES
9−splitDots variable =
10− go [] variable
11− where
12− go vars str =
13− case break (=='.') str of
14− (x,_:rest) | isOp x -> vars ++ [x ++ '.' : rest]
15− | otherwise -> go (vars ++ [x]) rest
16− (x,[]) -> vars ++ [x]
17
12
18
13
19−isTuple :: String -> Bool
14+isTuple :: Text -> Bool
20isTuple name =
15isTuple name =
21− take 6 name == "_Tuple"
16+ Text.isPrefixOf "_Tuple" name
17+ &&
22− && all Char.isDigit (drop 6 name)
18+ Text.all Char.isDigit (Text.drop 6 name)
23
19
24
20
21+
22+-- INFIX OPERATORS
23+
24+
25−isOp :: String -> Bool
25+isOp :: Text -> Bool
26isOp name =
26isOp name =
27− all isSymbol name
27+ Text.all isSymbol name
28
28
29
29
30isSymbol :: Char -> Bool
30isSymbol :: Char -> Bool
31isSymbol c =
31isSymbol c =
32− c /= '`' && (Char.isSymbol c || elem c "+-/*=.$<>:&|^?%#@~!")
32+ elem c ("+-/*=.<>:&|^?%#@~!" :: String)
src/AST/Literal.hs+2−1
@@ -2,13 +2,14 @@
2module AST.Literal where
2module AST.Literal where
3
3
4import qualified Data.Map as Map
4import qualified Data.Map as Map
5+import Data.Text (Text)
5
6
6
7
7data Literal
8data Literal
8 = IntNum Int
9 = IntNum Int
9 | FloatNum Double
10 | FloatNum Double
10 | Chr Char
11 | Chr Char
11− | Str String
12+ | Str Text
12 | Boolean Bool
13 | Boolean Bool
13 deriving (Eq, Ord)
14 deriving (Eq, Ord)
14
15
src/AST/Module/Name.hs+6−2
@@ -1,12 +1,16 @@
1+{-# OPTIONS_GHC -Wall #-}
2+{-# LANGUAGE OverloadedStrings #-}
1module AST.Module.Name where
3module AST.Module.Name where
2
4
3import Data.Binary
5import Data.Binary
4import qualified Data.List as List
6import qualified Data.List as List
7+import qualified Data.Text as Text
8+import Data.Text (Text)
5
9
6import qualified Elm.Package as Package
10import qualified Elm.Package as Package
7
11
8
12
9−type Raw = [String] -- must be non-empty
13+type Raw = [Text] -- must be non-empty
10
14
11
15
12data Canonical = Canonical
16data Canonical = Canonical
@@ -33,7 +37,7 @@ inHtml raw =
33
37
34toString :: Raw -> String
38toString :: Raw -> String
35toString rawName =
39toString rawName =
36− List.intercalate "." rawName
40+ List.intercalate "." (map Text.unpack rawName)
37
41
38
42
39canonicalToString :: Canonical -> String
43canonicalToString :: Canonical -> String
src/AST/Pattern.hs+26−27
@@ -1,8 +1,11 @@
1{-# OPTIONS_GHC -Wall #-}
1{-# OPTIONS_GHC -Wall #-}
2+{-# LANGUAGE OverloadedStrings #-}
2module AST.Pattern where
3module AST.Pattern where
3
4
4import qualified Data.List as List
5import qualified Data.List as List
5import qualified Data.Set as Set
6import qualified Data.Set as Set
7+import qualified Data.Text as Text
8+import Data.Text (Text)
6
9
7import qualified AST.Literal as L
10import qualified AST.Literal as L
8import qualified AST.Variable as Var
11import qualified AST.Variable as Var
@@ -15,10 +18,10 @@ type Pattern ann var =
15
18
16
19
17data Pattern' ann var
20data Pattern' ann var
18− = Data var [Pattern ann var]
21+ = Ctor var [Pattern ann var]
19− | Record [String]
22+ | Record [Text]
20− | Alias String (Pattern ann var)
23+ | Alias Text (Pattern ann var)
21− | Var String
24+ | Var Text
22 | Anything
25 | Anything
23 | Literal L.Literal
26 | Literal L.Literal
24
27
@@ -35,7 +38,7 @@ type Canonical =
35 Pattern R.Region Var.Canonical
38 Pattern R.Region Var.Canonical
36
39
37
40
38−isVar :: String -> Pattern ann var -> Bool
41+isVar :: Text -> Pattern ann var -> Bool
39isVar name (A.A _ pattern) =
42isVar name (A.A _ pattern) =
40 case pattern of
43 case pattern of
41 Var pName ->
44 Var pName ->
@@ -49,30 +52,26 @@ list :: R.Position -> [Raw] -> Raw
49list end patterns =
52list end patterns =
50 case patterns of
53 case patterns of
51 [] ->
54 [] ->
52− A.at end end (Data (Var.Raw "[]") [])
55+ A.at end end (Ctor (Var.Raw "[]") [])
53
56
54 pattern@(A.A (R.Region start _) _) : rest ->
57 pattern@(A.A (R.Region start _) _) : rest ->
55− A.at start end (Data (Var.Raw "::") [pattern, list end rest])
58+ A.at start end (Ctor (Var.Raw "::") [pattern, list end rest])
56−
57−
58−consMany :: R.Position -> [Raw] -> Raw
59−consMany end patterns =
60− let cons hd@(A.A (R.Region start _) _) tl =
61− A.at start end (Data (Var.Raw "::") [hd, tl])
62− in
63− foldr1 cons patterns
64
59
65
60
66tuple :: [Raw] -> Raw'
61tuple :: [Raw] -> Raw'
67tuple patterns =
62tuple patterns =
63+ let
64+ name =
68− Data (Var.Raw ("_Tuple" ++ show (length patterns))) patterns
65+ Text.append "_Tuple" (Text.pack (show (length patterns)))
66+ in
67+ Ctor (Var.Raw name) patterns
69
68
70
69
71
70
72-- FIND VARIABLES
71-- FIND VARIABLES
73
72
74
73
75−boundVars :: Pattern ann var -> [A.Annotated ann String]
74+boundVars :: Pattern ann var -> [A.Annotated ann Text]
76boundVars (A.A ann pattern) =
75boundVars (A.A ann pattern) =
77 case pattern of
76 case pattern of
78 Var x ->
77 Var x ->
@@ -81,7 +80,7 @@ boundVars (A.A ann pattern) =
81 Alias name realPattern ->
80 Alias name realPattern ->
82 A.A ann name : boundVars realPattern
81 A.A ann name : boundVars realPattern
83
82
84− Data _ patterns ->
83+ Ctor _ patterns ->
85 concatMap boundVars patterns
84 concatMap boundVars patterns
86
85
87 Record fields ->
86 Record fields ->
@@ -94,17 +93,17 @@ boundVars (A.A ann pattern) =
94 []
93 []
95
94
96
95
97−member :: String -> Pattern ann var -> Bool
96+member :: Text -> Pattern ann var -> Bool
98member name pattern =
97member name pattern =
99− any (name==) (map A.drop (boundVars pattern))
98+ elem name (map A.drop (boundVars pattern))
100
99
101
100
102−boundVarSet :: Pattern ann var -> Set.Set String
101+boundVarSet :: Pattern ann var -> Set.Set Text
103boundVarSet pattern =
102boundVarSet pattern =
104 Set.fromList (map A.drop (boundVars pattern))
103 Set.fromList (map A.drop (boundVars pattern))
105
104
106
105
107−boundVarList :: Pattern ann var -> [String]
106+boundVarList :: Pattern ann var -> [Text]
108boundVarList pattern =
107boundVarList pattern =
109 Set.toList (boundVarSet pattern)
108 Set.toList (boundVarSet pattern)
110
109
@@ -117,15 +116,15 @@ toString :: Bool -> Canonical -> String
117toString needsParens (A.A _ pattern) =
116toString needsParens (A.A _ pattern) =
118 case pattern of
117 case pattern of
119 Var name ->
118 Var name ->
120− name
119+ Text.unpack name
121
120
122− Data name [] ->
121+ Ctor name [] ->
123 if Var.isTuple name then
122 if Var.isTuple name then
124 "()"
123 "()"
125 else
124 else
126 Var.toString name
125 Var.toString name
127
126
128− Data name args ->
127+ Ctor name args ->
129 if Var.isTuple name then
128 if Var.isTuple name then
130 "( " ++ List.intercalate ", " (map (toString False) args) ++ " )"
129 "( " ++ List.intercalate ", " (map (toString False) args) ++ " )"
131 else
130 else
@@ -133,11 +132,11 @@ toString needsParens (A.A _ pattern) =
133 Var.toString name ++ concatMap ((" "++) . toString True) args
132 Var.toString name ++ concatMap ((" "++) . toString True) args
134
133
135 Record fields ->
134 Record fields ->
136− "{" ++ List.intercalate "," fields ++ "}"
135+ "{" ++ List.intercalate "," (map Text.unpack fields) ++ "}"
137
136
138 Alias alias subPattern ->
137 Alias alias subPattern ->
139 parensIf needsParens $
138 parensIf needsParens $
140− toString False subPattern ++ " as " ++ alias
139+ toString False subPattern ++ " as " ++ Text.unpack alias
141
140
142 Anything ->
141 Anything ->
143 "_"
142 "_"
src/AST/Type.hs+15−11
@@ -1,3 +1,5 @@
1+{-# OPTIONS_GHC -Wall #-}
2+{-# LANGUAGE OverloadedStrings #-}
1module AST.Type
3module AST.Type
2 ( Raw, Raw'(..)
4 ( Raw, Raw'(..)
3 , Canonical(..), Aliased(..)
5 , Canonical(..), Aliased(..)
@@ -10,6 +12,8 @@ module AST.Type
10import Control.Arrow (second)
12import Control.Arrow (second)
11import Data.Binary
13import Data.Binary
12import qualified Data.Map as Map
14import qualified Data.Map as Map
15+import qualified Data.Text as Text
16+import Data.Text (Text)
13
17
14import qualified AST.Module.Name as ModuleName
18import qualified AST.Module.Name as ModuleName
15import qualified AST.Variable as Var
19import qualified AST.Variable as Var
@@ -27,19 +31,19 @@ type Raw =
27
31
28data Raw'
32data Raw'
29 = RLambda Raw Raw
33 = RLambda Raw Raw
30− | RVar String
34+ | RVar Text
31 | RType Var.Raw
35 | RType Var.Raw
32 | RApp Raw [Raw]
36 | RApp Raw [Raw]
33− | RRecord [(A.Located String, Raw)] (Maybe Raw)
37+ | RRecord [(A.Located Text, Raw)] (Maybe Raw)
34
38
35
39
36data Canonical
40data Canonical
37 = Lambda Canonical Canonical
41 = Lambda Canonical Canonical
38− | Var String
42+ | Var Text
39 | Type Var.Canonical
43 | Type Var.Canonical
40 | App Canonical [Canonical]
44 | App Canonical [Canonical]
41− | Record [(String, Canonical)] (Maybe Canonical)
45+ | Record [(Text, Canonical)] (Maybe Canonical)
42− | Aliased Var.Canonical [(String, Canonical)] (Aliased Canonical)
46+ | Aliased Var.Canonical [(Text, Canonical)] (Aliased Canonical)
43 deriving (Eq, Ord)
47 deriving (Eq, Ord)
44
48
45
49
@@ -57,22 +61,22 @@ tuple :: R.Region -> [Raw] -> Raw
57tuple region types =
61tuple region types =
58 let
62 let
59 name =
63 name =
60− Var.Raw ("_Tuple" ++ show (length types))
64+ Var.Raw (Text.append "_Tuple" (Text.pack (show (length types))))
61 in
65 in
62 A.A region (RApp (A.A region (RType name)) types)
66 A.A region (RApp (A.A region (RType name)) types)
63
67
64
68
65−cmd :: ModuleName.Canonical -> String -> Canonical
69+cmd :: ModuleName.Canonical -> Text -> Canonical
66cmd =
70cmd =
67 effect Var.cmd
71 effect Var.cmd
68
72
69
73
70−sub :: ModuleName.Canonical -> String -> Canonical
74+sub :: ModuleName.Canonical -> Text -> Canonical
71sub =
75sub =
72 effect Var.sub
76 effect Var.sub
73
77
74
78
75−effect :: Var.Canonical -> ModuleName.Canonical -> String -> Canonical
79+effect :: Var.Canonical -> ModuleName.Canonical -> Text -> Canonical
76effect effectName moduleName tipe =
80effect effectName moduleName tipe =
77 Lambda
81 Lambda
78 (App (Type (Var.fromModule moduleName tipe)) [Var "msg"])
82 (App (Type (Var.fromModule moduleName tipe)) [Var "msg"])
@@ -115,7 +119,7 @@ iteratedDealias tipe =
115 tipe
119 tipe
116
120
117
121
118−dealias :: [(String, Canonical)] -> Aliased Canonical -> Canonical
122+dealias :: [(Text, Canonical)] -> Aliased Canonical -> Canonical
119dealias args aliasType =
123dealias args aliasType =
120 case aliasType of
124 case aliasType of
121 Holey tipe ->
125 Holey tipe ->
@@ -125,7 +129,7 @@ dealias args aliasType =
125 tipe
129 tipe
126
130
127
131
128−dealiasHelp :: Map.Map String Canonical -> Canonical -> Canonical
132+dealiasHelp :: Map.Map Text Canonical -> Canonical -> Canonical
129dealiasHelp typeTable tipe =
133dealiasHelp typeTable tipe =
130 let
134 let
131 go =
135 go =
src/AST/Variable.hs+26−19
@@ -1,7 +1,11 @@
1+{-# OPTIONS_GHC -Wall #-}
2+{-# LANGUAGE OverloadedStrings #-}
1module AST.Variable where
3module AST.Variable where
2
4
3import Data.Binary
5import Data.Binary
4import qualified Data.Maybe as Maybe
6import qualified Data.Maybe as Maybe
7+import qualified Data.Text as Text
8+import Data.Text (Text)
5
9
6import qualified AST.Helpers as Help
10import qualified AST.Helpers as Help
7import qualified AST.Module.Name as ModuleName
11import qualified AST.Module.Name as ModuleName
@@ -11,7 +15,7 @@ import qualified AST.Module.Name as ModuleName
11-- RAW NAMES
15-- RAW NAMES
12
16
13
17
14−newtype Raw = Raw String
18+newtype Raw = Raw Text
15 deriving (Eq, Ord)
19 deriving (Eq, Ord)
16
20
17
21
@@ -28,38 +32,38 @@ data Home
28
32
29
33
30data Canonical = Canonical
34data Canonical = Canonical
31− { home :: !Home
35+ { _home :: !Home
32− , name :: !String
36+ , _name :: !Text
33 }
37 }
34 deriving (Eq, Ord)
38 deriving (Eq, Ord)
35
39
36
40
37−local :: String -> Canonical
41+local :: Text -> Canonical
38local x =
42local x =
39 Canonical Local x
43 Canonical Local x
40
44
41
45
42−topLevel :: ModuleName.Canonical -> String -> Canonical
46+topLevel :: ModuleName.Canonical -> Text -> Canonical
43topLevel home x =
47topLevel home x =
44 Canonical (TopLevel home) x
48 Canonical (TopLevel home) x
45
49
46
50
47−builtin :: String -> Canonical
51+builtin :: Text -> Canonical
48builtin x =
52builtin x =
49 Canonical BuiltIn x
53 Canonical BuiltIn x
50
54
51
55
52−fromModule :: ModuleName.Canonical -> String -> Canonical
56+fromModule :: ModuleName.Canonical -> Text -> Canonical
53fromModule home name =
57fromModule home name =
54 Canonical (Module home) name
58 Canonical (Module home) name
55
59
56
60
57−inCore :: ModuleName.Raw -> String -> Canonical
61+inCore :: ModuleName.Raw -> Text -> Canonical
58inCore home name =
62inCore home name =
59 Canonical (Module (ModuleName.inCore home)) name
63 Canonical (Module (ModuleName.inCore home)) name
60
64
61
65
62−inHtml :: ModuleName.Raw -> String -> Canonical
66+inHtml :: ModuleName.Raw -> Text -> Canonical
63inHtml home name =
67inHtml home name =
64 Canonical (Module (ModuleName.inHtml home)) name
68 Canonical (Module (ModuleName.inHtml home)) name
65
69
@@ -94,7 +98,7 @@ isLocalHome home =
94 True
98 True
95
99
96
100
97−is :: ModuleName.Raw -> String -> Canonical -> Bool
101+is :: ModuleName.Raw -> Text -> Canonical -> Bool
98is home name var =
102is home name var =
99 var == inCore home name
103 var == inCore home name
100
104
@@ -126,8 +130,11 @@ isList v =
126isTuple :: Canonical -> Bool
130isTuple :: Canonical -> Bool
127isTuple v =
131isTuple v =
128 case v of
132 case v of
129− Canonical BuiltIn name -> Help.isTuple name
133+ Canonical BuiltIn name ->
134+ Help.isTuple name
135+
136+ _ ->
130− _ -> False
137+ False
131
138
132
139
133isPrimitive :: Canonical -> Bool
140isPrimitive :: Canonical -> Bool
@@ -139,7 +146,7 @@ isPrimitive v =
139 False
146 False
140
147
141
148
142−isPrim :: String -> Canonical -> Bool
149+isPrim :: Text -> Canonical -> Bool
143isPrim prim (Canonical home name) =
150isPrim prim (Canonical home name) =
144 case home of
151 case home of
145 BuiltIn ->
152 BuiltIn ->
@@ -149,7 +156,7 @@ isPrim prim (Canonical home name) =
149 False
156 False
150
157
151
158
152−isLocal :: (String -> Bool) -> Canonical -> Bool
159+isLocal :: (Text -> Bool) -> Canonical -> Bool
153isLocal check (Canonical home name) =
160isLocal check (Canonical home name) =
154 case home of
161 case home of
155 Local ->
162 Local ->
@@ -169,23 +176,23 @@ class ToString a where
169
176
170instance ToString Raw where
177instance ToString Raw where
171 toString (Raw name) =
178 toString (Raw name) =
172− name
179+ Text.unpack name
173
180
174
181
175instance ToString Canonical where
182instance ToString Canonical where
176 toString (Canonical home name) =
183 toString (Canonical home name) =
177 case home of
184 case home of
178 BuiltIn ->
185 BuiltIn ->
179− name
186+ Text.unpack name
180
187
181 Module moduleName ->
188 Module moduleName ->
182− ModuleName.canonicalToString moduleName ++ "." ++ name
189+ ModuleName.canonicalToString moduleName ++ "." ++ Text.unpack name
183
190
184 TopLevel _ ->
191 TopLevel _ ->
185− name
192+ Text.unpack name
186
193
187 Local ->
194 Local ->
188− name
195+ Text.unpack name
189
196
190
197
191
198