@@ -122,40 +122,40 @@ instantiator env sourceType = go sourceType
123 Src.Var x -> do
123 Src.Var x -> do
124 (dict, aliases) <- State.get
124 (dict, aliases) <- State.get
125− case Map.lookup x dict of
125+ case (Map.lookup x dict, Map.lookup x aliases) of
126− Just var -> return (VarN var)
128− case Map.lookup x aliases of
129− Just t -> return t
126+ (_, Just t) -> return t
130− Nothing ->
127+ (Just v, _) -> return (VarN v)
131− do var <- State.liftIO $ namedVar flex x
129+ do var <- State.liftIO $ namedVar flex x
132− State.put (Map.insert x var dict, aliases)
130+ State.put (Map.insert x var dict, aliases)
133− return (VarN var)
131+ return (VarN var)
135− flex | "number" `isPrefixOf` x = Is Number
133+ flex | "number" `isPrefixOf` x = Is Number
136− | "comparable" `isPrefixOf` x = Is Comparable
134+ | "comparable" `isPrefixOf` x = Is Comparable
137− | "appendable" `isPrefixOf` x = Is Appendable
135+ | "appendable" `isPrefixOf` x = Is Appendable
138− | otherwise = Flexible
136+ | otherwise = Flexible
140 Src.Data "String" [] ->
138 Src.Data "String" [] ->
141 return (get env types "_List" <| get env types "Char")
139 return (get env types "_List" <| get env types "Char")
143 Src.Data name ts -> do
141 Src.Data name ts -> do
144 ts' <- mapM go ts
142 ts' <- mapM go ts
145− case Map.lookup name (types env) of
143+ case (Map.lookup name (types env), Map.lookup name (aliases env)) of
146− Just t -> return $ foldl (<|) t ts'
144+ (Just t, _) -> return $ foldl (<|) t ts'
148− case Map.lookup name (aliases env) of
149− Nothing -> error $ "\nCould not find type constructor '" ++ name ++ "' while checking types."
150− Just (tvars, t) ->
145+ (_, Just (tvars, t)) ->
151− let tvarLen = length tvars
146+ let tvarLen = length tvars
152− msg = "\nType alias '" ++ name ++ "' expects " ++ show tvarLen ++
147+ msg = "\nType alias '" ++ name ++ "' expects " ++ show tvarLen ++
153− " type argument" ++ (if tvarLen == 1 then "" else "s") ++
148+ " type argument" ++ (if tvarLen == 1 then "" else "s") ++
154− " but was given " ++ show (length ts')
149+ " but was given " ++ show (length ts')
155− in if length ts' /= length tvars then error msg else
150+ in if length ts' /= length tvars then error msg else
156− do (dict, aliases) <- State.get
151+ do (dict, aliases) <- State.get
157− State.put (dict, Map.union aliases . Map.fromList $ zip tvars ts')
152+ let aliases' = Map.union (Map.fromList $ zip tvars ts') aliases
153+ State.put (dict, aliases')
155+ State.put (dict, aliases)
157+ _ -> error $ "\nCould not find type constructor '" ++
158+ name ++ "' while checking types."
160 Src.EmptyRecord -> return (TermN EmptyRecord1)
160 Src.EmptyRecord -> return (TermN EmptyRecord1)