@@ -10,7 +10,7 @@ import qualified Data.Map as Map
1010import qualified Data.Set as Set
1111
1212import Ast
13−import Context
13+import Located
1414import Guid
1515
1616import Types.Types
@@ -62,7 +62,7 @@ mergeSchemes schmss = do (ass,css,sss) <- unzip3 `liftM` mapM split kvs
6262 kvs = Map.toList $ Map.unionsWith (++) (map (Map.map (:[])) schmss)
6363 split (k,vs) =
6464 let ps = zipWith (\s v -> (s++k,v)) (map (flip replicate '_') [0..]) vs
65− eq t u = C (Just $ msg ++ k) NoSpan (VarT t :=: VarT u)
65+ eq t u = L (Just $ msg ++ k) NoSpan (VarT t :=: VarT u)
6666 msg = "the definition of "
6767 in do xs <- mapM (\_ -> guid) vs
6868 return ( Map.fromList $ zip (map fst ps) (map (:[]) xs)
@@ -81,7 +81,7 @@ constrain typeHints (Module _ _ imports stmts) = do
8181 insert as n = do v <- guid; return $ Map.insertWith' (\_ x -> x) n [v] as
8282 assumptions <- foldM insert as (Map.keys schemes)
8383 findAmbiguous (map fst aliasHints) assumptions $ do
84− let f k s vs = map (\v -> C (Just k) NoSpan $ v :<<: s) vs
84+ let f k s vs = map (\v -> L (Just k) NoSpan $ v :<<: s) vs
8585 cs = concat . Map.elems $ Map.intersectionWithKey f allHints assumptions
8686 escapees = Map.keys $ Map.difference assumptions allHints
8787 msg = "Warning! Type-checker could not find variables:\n" ++ intercalate ", " escapees
@@ -91,13 +91,13 @@ constrain typeHints (Module _ _ imports stmts) = do
9191 --_ -> Left ("Undefined variable(s): " ++ intercalate ", " escapees)
9292
9393type TVarMap = Map.Map String [X]
94−type ConstraintSet = Set.Set (Context Constraint)
94+type ConstraintSet = Set.Set (Located Constraint)
9595
96−ctx e span = C (Just $ show e) span
96+loc e span = L (Just $ show e) span
9797
9898gen :: CExpr -> GuidCounter (TVarMap, ConstraintSet, Type)
99−gen (C _ span expr) =
100− let ctx' = C (Just $ show expr) span in
99+gen (L _ span expr) =
100+ let loc' = L (Just $ show expr) span in
101101 case expr of
102102 Var x ->
103103 do b <- guid
@@ -109,7 +109,7 @@ gen (C _ span expr) =
109109 b <- beta
110110 return ( unionA a1 a2
111111 , Set.unions [c1,c2
112− ,Set.singleton . ctx' $ t1 :=: (LambdaT t2 b)]
112+ ,Set.singleton . loc' $ t1 :=: (LambdaT t2 b)]
113113 , b )
114114
115115 Lambda x e ->
@@ -118,7 +118,7 @@ gen (C _ span expr) =
118118 v <- guid
119119 return ( Map.delete x a
120120 , Set.union c . Set.fromList .
121− map (\x -> ctx' $ VarT x :=: b) $
121+ map (\x -> loc' $ VarT x :=: b) $
122122 Map.findWithDefault [v] x a
123123 , LambdaT b t )
124124
@@ -132,7 +132,7 @@ gen (C _ span expr) =
132132 genCs name s = do
133133 v <- guid
134134 let vs = Map.findWithDefault [v] name assumptions
135− return $ map (\x -> ctx name span $ x :<<: s) vs
135+ return $ map (\x -> loc name span $ x :<<: s) vs
136136 cs' <- zipWithM genCs names schemes
137137 return ( foldr Map.delete assumptions names
138138 , Set.union (Set.fromList . concat $ cs') cs
@@ -143,9 +143,9 @@ gen (C _ span expr) =
143143 (ass,css,ts) <- liftM unzip3 $ mapM (caseGen t) cases
144144 return ( unionsA $ as:ass
145145 , let cases' = map snd cases
146− ctxs = zipWith epos cases' (tail cases')
146+ locs = zipWith epos cases' (tail cases')
147147 csts = zipWith (:=:) ts (tail ts)
148− cs' = Set.fromList (zipWith ($) ctxs csts)
148+ cs' = Set.fromList (zipWith ($) locs csts)
149149 in Set.unions $ cs' : cs : css
150150 , head ts)
151151
@@ -154,30 +154,30 @@ gen (C _ span expr) =
154154 (a2,c2,t2) <- gen e2
155155 (a3,c3,t3) <- gen e3
156156 return ( unionsA [a1,a2,a3]
157− , let c4 = Set.fromList [ ctx e1 span (t1 :=: bool)
158− , ctx' (t2 :=: t3) ]
157+ , let c4 = Set.fromList [ loc e1 span (t1 :=: bool)
158+ , loc' (t2 :=: t3) ]
159159 in Set.unions [c1,c2,c3,c4]
160160 , t2 )
161161
162162 Data name es ->
163− gen $ foldl' (\f x -> epos f x $ App f x) (ctx' $ Var name) es
163+ gen $ foldl' (\f x -> epos f x $ App f x) (loc' $ Var name) es
164164
165165 Binop op e1 e2 ->
166− gen $ ctx' (App (ctx' $ App (ctx' $ Var op) e1) e2)
166+ gen $ loc' (App (loc' $ App (loc' $ Var op) e1) e2)
167167
168168 Access e label ->
169169 do (as,cs,rtype) <- gen e
170170 t <- beta
171171 rtype' <- beta
172172 let fs = Map.singleton label [t]
173− c = (ctx' (RecordT fs rtype' :=: rtype))
173+ c = (loc' (RecordT fs rtype' :=: rtype))
174174 return (as, Set.insert c cs, t)
175175
176176 Remove e x ->
177177 do (as,cs,rtype) <- gen e
178178 t <- beta
179179 rtype' <- beta
180− let c = (ctx' (RecordT (Map.singleton x [t]) rtype' :=: rtype))
180+ let c = (loc' (RecordT (Map.singleton x [t]) rtype' :=: rtype))
181181 return (as, Set.insert c cs, rtype')
182182
183183 Insert e x v ->
@@ -193,7 +193,7 @@ gen (C _ span expr) =
193193 oldTs <- mapM (\_ -> beta) fields
194194 rtype' <- beta
195195 let rT ts = RecordT (recordT (zip (map fst fields) ts)) rtype'
196− c = Set.singleton (ctx' (rtype :=: rT oldTs))
196+ c = Set.singleton (loc' (rtype :=: rT oldTs))
197197 return ( unionsA (ras:ass), Set.unions (c : rcs : css), rT newTs )
198198
199199 Record fields ->
@@ -206,27 +206,27 @@ gen (C _ span expr) =
206206 , Set.fromList (concat css)
207207 , RecordT (foldr ($) Map.empty fs) EmptyRecord )
208208
209− Range e1@(C w1 s1 _) e2@(C w2 s2 _) ->
209+ Range e1@(L w1 s1 _) e2@(L w2 s2 _) ->
210210 do (a1,c1,t1) <- gen e1
211211 (a2,c2,t2) <- gen e2
212212 return ( unionsA [a1,a2]
213− , Set.unions [ c1, c2, Set.fromList [ C w1 s1 (t1 :=: int)
214− , C w1 s2 (t2 :=: int) ] ]
213+ , Set.unions [ c1, c2, Set.fromList [ L w1 s1 (t1 :=: int)
214+ , L w1 s2 (t2 :=: int) ] ]
215215 , listOf int )
216216
217217 MultiIf ps -> do (ass,css,t:ts) <- unzip3 `liftM` mapM genPair ps
218− let cs = Set.fromList (map (ctx' . (t :=:)) ts)
218+ let cs = Set.fromList (map (loc' . (t :=:)) ts)
219219 return (unionsA ass, Set.unions (cs:css), t)
220− where genPair (b@(C t s _),e) = do
220+ where genPair (b@(L t s _),e) = do
221221 (a1,c1,t1) <- gen b
222222 (a2,c2,t2) <- gen e
223223 return ( unionsA [a1,a2]
224224 , Set.unions [ c1, c2
225− , Set.singleton (C t s (t1 :=: bool)) ]
225+ , Set.singleton (L t s (t1 :=: bool)) ]
226226 , t2 )
227227
228228 IntNum _ -> do t <- beta
229− return (Map.empty, Set.singleton (ctx' $ t :<: number), t)
229+ return (Map.empty, Set.singleton (loc' $ t :<: number), t)
230230
231231 FloatNum _ -> primitive float
232232 Chr _ -> primitive char
@@ -241,41 +241,41 @@ primitive t = return (Map.empty, Set.empty, t)
241241caseGen :: Type
242242 -> (Pattern, CExpr)
243243 -> GuidCounter (TVarMap, ConstraintSet, Type)
244−caseGen tipe (p, ce@(C _ span e)) = do
244+caseGen tipe (p, ce@(L _ span e)) = do
245245 (as ,cs ,t) <- gen ce
246− (as',cs',_) <- patternGen (ctx p span) tipe as p
246+ (as',cs',_) <- patternGen (loc p span) tipe as p
247247 return ( as', Set.union cs cs', t )
248248
249−patternGen :: (Constraint -> Context Constraint)
249+patternGen :: (Constraint -> Located Constraint)
250250 -> Type -- Type of e in `case e of ...`
251251 -> TVarMap
252252 -> Pattern
253253 -> GuidCounter (TVarMap, ConstraintSet, Type)
254−patternGen ctxt tipe as pattern =
254+patternGen loc tipe as pattern =
255255 case pattern of
256256 PAnything -> do b <- beta ; return ( as, Set.empty, b )
257257 PVar v -> do
258258 b <- beta
259− let cs = map (ctxt . (b :=:) . VarT) (Map.findWithDefault [] v as)
260− return ( Map.delete v as, Set.fromList (ctxt (b :=: tipe) : cs), b )
259+ let cs = map (loc . (b :=:) . VarT) (Map.findWithDefault [] v as)
260+ return ( Map.delete v as, Set.fromList (loc (b :=: tipe) : cs), b )
261261 PData name ps -> do
262262 constr <- guid
263263 output <- beta
264264 let step (as,cs,tipe) p = do b <- beta
265− (as',cs',t) <- patternGen ctxt b as p
265+ (as',cs',t) <- patternGen loc b as p
266266 return (as', Set.union cs cs', t ==> tipe)
267267 (as',cs, t) <- foldM step (as,Set.empty,tipe) (reverse ps)
268268 return ( Map.insert name [constr] as'
269− , Set.insert (ctxt (VarT constr :=: t)) cs
269+ , Set.insert (loc (VarT constr :=: t)) cs
270270 , output )
271271 PRecord fs ->
272272 do pairs <- mapM (\f -> do b <- beta; return (f,b)) fs
273273 b <- beta
274274 let t = RecordT (Map.fromList $ map (second (:[])) pairs) b
275− mkCs (name,tipe) = map (ctxt . (tipe :=:) . VarT)
275+ mkCs (name,tipe) = map (loc . (tipe :=:) . VarT)
276276 (Map.findWithDefault [] name as)
277277 return ( foldr Map.delete as fs
278− , Set.fromList (ctxt (t :=: tipe) : concatMap mkCs pairs)
278+ , Set.fromList (loc (t :=: tipe) : concatMap mkCs pairs)
279279 , t )
280280
281281
@@ -295,7 +295,7 @@ defGenHelp name args e = do
295295 genCs (arg,x) = do
296296 v <- guid
297297 let as' = Map.findWithDefault [v] arg as
298− return $ map (\y -> ctx arg NoSpan $ VarT x :=: VarT y) as'
298+ return $ map (\y -> loc arg NoSpan $ VarT x :=: VarT y) as'
299299 cs' <- concat `liftM` mapM genCs argDict
300300 scheme <- Subs.generalize (concat $ Map.elems as') $
301301 Forall (map snd argDict) (cs' ++ Set.toList cs) tipe
@@ -316,13 +316,13 @@ stmtGen stmt =
316316 ExportEvent js elm tipe ->
317317 do x <- guid
318318 return ( Map.singleton elm [x]
319− , Set.singleton . ctx elm NoSpan $ VarT x :=: tipe
319+ , Set.singleton . loc elm NoSpan $ VarT x :=: tipe
320320 , Map.empty )
321321
322− ImportEvent js e@(C txt span base) elm tipe ->
322+ ImportEvent js e@(L txt span base) elm tipe ->
323323 do (as,cs,t) <- gen e
324324 return ( as
325− , Set.insert (C txt span (signalOf t :=: tipe)) cs
325+ , Set.insert (L txt span (signalOf t :=: tipe)) cs
326326 , Map.singleton elm (Forall [] [] tipe) )
327327
328328 TypeAnnotation name tipe ->