@@ -35,8 +35,9 @@ import qualified Data.Text as Text
35import Data.Text (Text)
35import Data.Text (Text)
36import Data.Word (Word32)
36import Data.Word (Word32)
38+import qualified AST.Canonical as Can
38import qualified AST.Module.Name as ModuleName
39import qualified AST.Module.Name as ModuleName
39−import qualified AST.Type as T
40+import qualified AST.Utils.Type as Type
40import qualified Elm.Name as N
41import qualified Elm.Name as N
41import qualified Type.UnionFind as UF
42import qualified Type.UnionFind as UF
@@ -85,14 +86,21 @@ data Descriptor =
86data Content
87data Content
87 = FlexVar (Maybe N.Name)
88 = FlexVar (Maybe N.Name)
88− | FlexSuper T.Super (Maybe N.Name)
89+ | FlexSuper SuperType (Maybe N.Name)
89 | RigidVar N.Name
90 | RigidVar N.Name
90− | RigidSuper T.Super N.Name
91+ | RigidSuper SuperType N.Name
91 | Structure FlatType
92 | Structure FlatType
92 | Alias ModuleName.Canonical N.Name [(N.Name,Variable)] Variable
93 | Alias ModuleName.Canonical N.Name [(N.Name,Variable)] Variable
93 | Error Text
94 | Error Text
96makeDescriptor :: Content -> Descriptor
104makeDescriptor :: Content -> Descriptor
97makeDescriptor content =
105makeDescriptor content =
98 Descriptor content noRank noMark Nothing
106 Descriptor content noRank noMark Nothing
@@ -245,10 +253,10 @@ mkFlexNumber =
245{-# NOINLINE flexNumberDescriptor #-}
253{-# NOINLINE flexNumberDescriptor #-}
246flexNumberDescriptor :: Descriptor
254flexNumberDescriptor :: Descriptor
247flexNumberDescriptor =
255flexNumberDescriptor =
248− makeDescriptor (unnamedFlexSuper T.Number)
256+ makeDescriptor (unnamedFlexSuper Number)
251−unnamedFlexSuper :: T.Super -> Content
259+unnamedFlexSuper :: SuperType -> Content
252unnamedFlexSuper super =
260unnamedFlexSuper super =
253 FlexSuper super Nothing
261 FlexSuper super Nothing
@@ -269,19 +277,19 @@ nameToRigid name =
269 maybe RigidVar RigidSuper (toSuper name) name
277 maybe RigidVar RigidSuper (toSuper name) name
272−toSuper :: N.Name -> Maybe T.Super
280+toSuper :: N.Name -> Maybe SuperType
273toSuper name =
281toSuper name =
274 if Text.isPrefixOf "number" name then
282 if Text.isPrefixOf "number" name then
275− Just T.Number
283+ Just Number
277 else if Text.isPrefixOf "comparable" name then
285 else if Text.isPrefixOf "comparable" name then
278− Just T.Comparable
286+ Just Comparable
280 else if Text.isPrefixOf "appendable" name then
288 else if Text.isPrefixOf "appendable" name then
281− Just T.Appendable
289+ Just Appendable
283 else if Text.isPrefixOf "compappend" name then
291 else if Text.isPrefixOf "compappend" name then
284− Just T.CompAppend
292+ Just CompAppend
@@ -293,19 +301,19 @@ toSuper name =
294-- TODO: Attach resulting type to the descriptor so that you
302-- TODO: Attach resulting type to the descriptor so that you
295-- never have to do extra work, particularly nice for aliased types
303-- never have to do extra work, particularly nice for aliased types
296−toSrcType :: Variable -> IO T.Canonical
304+toSrcType :: Variable -> IO Can.Type
297toSrcType variable =
305toSrcType variable =
298 do takenNames <- getVarNames variable Map.empty
306 do takenNames <- getVarNames variable Map.empty
299 State.evalStateT (variableToSrcType variable) (makeNameState takenNames)
307 State.evalStateT (variableToSrcType variable) (makeNameState takenNames)
302−variableToSrcType :: Variable -> StateT NameState IO T.Canonical
310+variableToSrcType :: Variable -> StateT NameState IO Can.Type
303variableToSrcType variable =
311variableToSrcType variable =
304 do descriptor <- liftIO $ UF.descriptor variable
312 do descriptor <- liftIO $ UF.descriptor variable
305 let mark = _mark descriptor
313 let mark = _mark descriptor
306 if mark == occursMark
314 if mark == occursMark
308− return (T.Var "∞")
316+ return (Can.TVar "∞")
311 do liftIO $ UF.modifyDescriptor variable (\desc -> desc { _mark = occursMark })
319 do liftIO $ UF.modifyDescriptor variable (\desc -> desc { _mark = occursMark })
@@ -314,7 +322,7 @@ variableToSrcType variable =
314 return srcType
322 return srcType
317−contentToSrcType :: Variable -> Content -> StateT NameState IO T.Canonical
325+contentToSrcType :: Variable -> Content -> StateT NameState IO Can.Type
318contentToSrcType variable content =
326contentToSrcType variable content =
319 case content of
327 case content of
320 Structure term ->
328 Structure term ->
@@ -323,71 +331,71 @@ contentToSrcType variable content =
323 FlexVar maybeName ->
331 FlexVar maybeName ->
324 case maybeName of
332 case maybeName of
325 Just name ->
333 Just name ->
326− return (T.Var name)
334+ return (Can.TVar name)
328 Nothing ->
336 Nothing ->
329 do name <- getFreshVarName
337 do name <- getFreshVarName
330 liftIO $ UF.modifyDescriptor variable (\desc -> desc { _content = FlexVar (Just name) })
338 liftIO $ UF.modifyDescriptor variable (\desc -> desc { _content = FlexVar (Just name) })
331− return (T.Var name)
339+ return (Can.TVar name)
333 FlexSuper super maybeName ->
341 FlexSuper super maybeName ->
334 case maybeName of
342 case maybeName of
335 Just name ->
343 Just name ->
336− return (T.Var name)
344+ return (Can.TVar name)
338 Nothing ->
346 Nothing ->
339 do name <- getFreshSuperName super
347 do name <- getFreshSuperName super
340 liftIO $ UF.modifyDescriptor variable (\desc -> desc { _content = FlexSuper super (Just name) })
348 liftIO $ UF.modifyDescriptor variable (\desc -> desc { _content = FlexSuper super (Just name) })
341− return (T.Var name)
349+ return (Can.TVar name)
343 RigidVar name ->
351 RigidVar name ->
344− return (T.Var name)
352+ return (Can.TVar name)
346 RigidSuper _ name ->
354 RigidSuper _ name ->
347− return (T.Var name)
355+ return (Can.TVar name)
349 Alias home name args realVariable ->
357 Alias home name args realVariable ->
350 do srcArgs <- traverse (traverse variableToSrcType) args
358 do srcArgs <- traverse (traverse variableToSrcType) args
351 srcType <- variableToSrcType realVariable
359 srcType <- variableToSrcType realVariable
352− return (T.Aliased home name srcArgs (T.Filled srcType))
360+ return (Can.TAlias home name srcArgs (Can.Filled srcType))
354 Error name ->
362 Error name ->
355− return (T.Var name)
363+ return (Can.TVar name)
358−termToSrcType :: FlatType -> StateT NameState IO T.Canonical
366+termToSrcType :: FlatType -> StateT NameState IO Can.Type
359termToSrcType term =
367termToSrcType term =
360 case term of
368 case term of
361 App1 home name args ->
369 App1 home name args ->
362− T.Type home name <$> traverse variableToSrcType args
370+ Can.TType home name <$> traverse variableToSrcType args
364 Fun1 a b ->
372 Fun1 a b ->
365− T.Lambda
373+ Can.TLambda
366 <$> variableToSrcType a
374 <$> variableToSrcType a
367 <*> variableToSrcType b
375 <*> variableToSrcType b
369 EmptyRecord1 ->
377 EmptyRecord1 ->
370− return $ T.Record Map.empty Nothing
378+ return $ Can.TRecord Map.empty Nothing
372 Record1 fields extension ->
380 Record1 fields extension ->
373 do srcFields <- traverse variableToSrcType fields
381 do srcFields <- traverse variableToSrcType fields
374− srcExt <- T.iteratedDealias <$> variableToSrcType extension
382+ srcExt <- Type.iteratedDealias <$> variableToSrcType extension
376 case srcExt of
384 case srcExt of
377− T.Record subFields subExt ->
385+ Can.TRecord subFields subExt ->
378− T.Record (Map.union subFields srcFields) subExt
386+ Can.TRecord (Map.union subFields srcFields) subExt
380− T.Var _ ->
388+ Can.TVar _ ->
381− T.Record srcFields (Just srcExt)
389+ Can.TRecord srcFields (Just srcExt)
384 error "Used toSrcType on a type that is not well-formed"
392 error "Used toSrcType on a type that is not well-formed"
387− return T.Unit
395+ return Can.TUnit
389 Tuple1 a b maybeC ->
397 Tuple1 a b maybeC ->
390− T.Tuple
398+ Can.TTuple
391 <$> variableToSrcType a
399 <$> variableToSrcType a
392 <*> variableToSrcType b
400 <*> variableToSrcType b
393 <*> traverse variableToSrcType maybeC
401 <*> traverse variableToSrcType maybeC
@@ -425,19 +433,19 @@ getFreshVarName =
425 return uniqueName
433 return uniqueName
428−getFreshSuperName :: (Monad m) => T.Super -> StateT NameState m Text
436+getFreshSuperName :: (Monad m) => SuperType -> StateT NameState m Text
429getFreshSuperName super =
437getFreshSuperName super =
430 case super of
438 case super of
431− T.Number ->
439+ Number ->
432 getFreshSuper "number" _numbers (\index state -> state { _numbers = index })
440 getFreshSuper "number" _numbers (\index state -> state { _numbers = index })
434− T.Comparable ->
442+ Comparable ->
435 getFreshSuper "comparable" _comparables (\index state -> state { _comparables = index })
443 getFreshSuper "comparable" _comparables (\index state -> state { _comparables = index })
437− T.Appendable ->
445+ Appendable ->
438 getFreshSuper "appendable" _appendables (\index state -> state { _appendables = index })
446 getFreshSuper "appendable" _appendables (\index state -> state { _appendables = index })
440− T.CompAppend ->
448+ CompAppend ->
441 getFreshSuper "compappend" _compAppends (\index state -> state { _compAppends = index })
449 getFreshSuper "compappend" _compAppends (\index state -> state { _compAppends = index })