@@ -35,8 +35,9 @@ import qualified Data.Text as Text
3535import Data.Text (Text)
3636import Data.Word (Word32)
3737
38+import qualified AST.Canonical as Can
3839import qualified AST.Module.Name as ModuleName
39−import qualified AST.Type as T
40+import qualified AST.Utils.Type as Type
4041import qualified Elm.Name as N
4142import qualified Type.UnionFind as UF
4243
@@ -85,14 +86,21 @@ data Descriptor =
8586
8687data Content
8788 = FlexVar (Maybe N.Name)
88− | FlexSuper T.Super (Maybe N.Name)
89+ | FlexSuper SuperType (Maybe N.Name)
8990 | RigidVar N.Name
90− | RigidSuper T.Super N.Name
91+ | RigidSuper SuperType N.Name
9192 | Structure FlatType
9293 | Alias ModuleName.Canonical N.Name [(N.Name,Variable)] Variable
9394 | Error Text
9495
9596
97+data SuperType
98+ = Number
99+ | Comparable
100+ | Appendable
101+ | CompAppend
102+
103+
96104makeDescriptor :: Content -> Descriptor
97105makeDescriptor content =
98106 Descriptor content noRank noMark Nothing
@@ -245,10 +253,10 @@ mkFlexNumber =
245253{-# NOINLINE flexNumberDescriptor #-}
246254flexNumberDescriptor :: Descriptor
247255flexNumberDescriptor =
248− makeDescriptor (unnamedFlexSuper T.Number)
256+ makeDescriptor (unnamedFlexSuper Number)
249257
250258
251−unnamedFlexSuper :: T.Super -> Content
259+unnamedFlexSuper :: SuperType -> Content
252260unnamedFlexSuper super =
253261 FlexSuper super Nothing
254262
@@ -269,19 +277,19 @@ nameToRigid name =
269277 maybe RigidVar RigidSuper (toSuper name) name
270278
271279
272−toSuper :: N.Name -> Maybe T.Super
280+toSuper :: N.Name -> Maybe SuperType
273281toSuper name =
274282 if Text.isPrefixOf "number" name then
275− Just T.Number
283+ Just Number
276284
277285 else if Text.isPrefixOf "comparable" name then
278− Just T.Comparable
286+ Just Comparable
279287
280288 else if Text.isPrefixOf "appendable" name then
281− Just T.Appendable
289+ Just Appendable
282290
283291 else if Text.isPrefixOf "compappend" name then
284− Just T.CompAppend
292+ Just CompAppend
285293
286294 else
287295 Nothing
@@ -293,19 +301,19 @@ toSuper name =
293301
294302-- TODO: Attach resulting type to the descriptor so that you
295303-- never have to do extra work, particularly nice for aliased types
296−toSrcType :: Variable -> IO T.Canonical
304+toSrcType :: Variable -> IO Can.Type
297305toSrcType variable =
298306 do takenNames <- getVarNames variable Map.empty
299307 State.evalStateT (variableToSrcType variable) (makeNameState takenNames)
300308
301309
302−variableToSrcType :: Variable -> StateT NameState IO T.Canonical
310+variableToSrcType :: Variable -> StateT NameState IO Can.Type
303311variableToSrcType variable =
304312 do descriptor <- liftIO $ UF.descriptor variable
305313 let mark = _mark descriptor
306314 if mark == occursMark
307315 then
308− return (T.Var "∞")
316+ return (Can.TVar "∞")
309317
310318 else
311319 do liftIO $ UF.modifyDescriptor variable (\desc -> desc { _mark = occursMark })
@@ -314,7 +322,7 @@ variableToSrcType variable =
314322 return srcType
315323
316324
317−contentToSrcType :: Variable -> Content -> StateT NameState IO T.Canonical
325+contentToSrcType :: Variable -> Content -> StateT NameState IO Can.Type
318326contentToSrcType variable content =
319327 case content of
320328 Structure term ->
@@ -323,71 +331,71 @@ contentToSrcType variable content =
323331 FlexVar maybeName ->
324332 case maybeName of
325333 Just name ->
326− return (T.Var name)
334+ return (Can.TVar name)
327335
328336 Nothing ->
329337 do name <- getFreshVarName
330338 liftIO $ UF.modifyDescriptor variable (\desc -> desc { _content = FlexVar (Just name) })
331− return (T.Var name)
339+ return (Can.TVar name)
332340
333341 FlexSuper super maybeName ->
334342 case maybeName of
335343 Just name ->
336− return (T.Var name)
344+ return (Can.TVar name)
337345
338346 Nothing ->
339347 do name <- getFreshSuperName super
340348 liftIO $ UF.modifyDescriptor variable (\desc -> desc { _content = FlexSuper super (Just name) })
341− return (T.Var name)
349+ return (Can.TVar name)
342350
343351 RigidVar name ->
344− return (T.Var name)
352+ return (Can.TVar name)
345353
346354 RigidSuper _ name ->
347− return (T.Var name)
355+ return (Can.TVar name)
348356
349357 Alias home name args realVariable ->
350358 do srcArgs <- traverse (traverse variableToSrcType) args
351359 srcType <- variableToSrcType realVariable
352− return (T.Aliased home name srcArgs (T.Filled srcType))
360+ return (Can.TAlias home name srcArgs (Can.Filled srcType))
353361
354362 Error name ->
355− return (T.Var name)
363+ return (Can.TVar name)
356364
357365
358−termToSrcType :: FlatType -> StateT NameState IO T.Canonical
366+termToSrcType :: FlatType -> StateT NameState IO Can.Type
359367termToSrcType term =
360368 case term of
361369 App1 home name args ->
362− T.Type home name <$> traverse variableToSrcType args
370+ Can.TType home name <$> traverse variableToSrcType args
363371
364372 Fun1 a b ->
365− T.Lambda
373+ Can.TLambda
366374 <$> variableToSrcType a
367375 <*> variableToSrcType b
368376
369377 EmptyRecord1 ->
370− return $ T.Record Map.empty Nothing
378+ return $ Can.TRecord Map.empty Nothing
371379
372380 Record1 fields extension ->
373381 do srcFields <- traverse variableToSrcType fields
374− srcExt <- T.iteratedDealias <$> variableToSrcType extension
382+ srcExt <- Type.iteratedDealias <$> variableToSrcType extension
375383 return $
376384 case srcExt of
377− T.Record subFields subExt ->
378− T.Record (Map.union subFields srcFields) subExt
385+ Can.TRecord subFields subExt ->
386+ Can.TRecord (Map.union subFields srcFields) subExt
379387
380− T.Var _ ->
381− T.Record srcFields (Just srcExt)
388+ Can.TVar _ ->
389+ Can.TRecord srcFields (Just srcExt)
382390
383391 _ ->
384392 error "Used toSrcType on a type that is not well-formed"
385393
386394 Unit1 ->
387− return T.Unit
395+ return Can.TUnit
388396
389397 Tuple1 a b maybeC ->
390− T.Tuple
398+ Can.TTuple
391399 <$> variableToSrcType a
392400 <*> variableToSrcType b
393401 <*> traverse variableToSrcType maybeC
@@ -425,19 +433,19 @@ getFreshVarName =
425433 return uniqueName
426434
427435
428−getFreshSuperName :: (Monad m) => T.Super -> StateT NameState m Text
436+getFreshSuperName :: (Monad m) => SuperType -> StateT NameState m Text
429437getFreshSuperName super =
430438 case super of
431− T.Number ->
439+ Number ->
432440 getFreshSuper "number" _numbers (\index state -> state { _numbers = index })
433441
434− T.Comparable ->
442+ Comparable ->
435443 getFreshSuper "comparable" _comparables (\index state -> state { _comparables = index })
436444
437− T.Appendable ->
445+ Appendable ->
438446 getFreshSuper "appendable" _appendables (\index state -> state { _appendables = index })
439447
440− T.CompAppend ->
448+ CompAppend ->
441449 getFreshSuper "compappend" _compAppends (\index state -> state { _compAppends = index })
442450
443451