@@ -75,14 +75,14 @@ a ==> b = TermN (Fun1 a b)
7575
7676f <| a = TermN (App1 f a)
7777
78−data Descriptor = Descriptor {
79− structure :: Maybe (Term1 Variable),
80− rank :: Int,
81− flex :: Flex,
82− name :: Maybe TypeName,
83− copy :: Maybe Variable,
84− mark :: Int
85−} deriving Show
78+data Descriptor = Descriptor
79+ { structure :: Maybe (Term1 Variable)
80+ , rank :: Int
81+ , flex :: Flex
82+ , name :: Maybe TypeName
83+ , copy :: Maybe Variable
84+ , mark :: Int
85+ } deriving Show
8686
8787noRank = -1
8888outermostRank = 0 :: Int
@@ -97,33 +97,23 @@ data SuperType = Number | Comparable | Appendable
9797 deriving (Show, Eq)
9898
9999namedVar :: Flex -> Var.Canonical -> IO Variable
100−namedVar flex name = UF.fresh $ Descriptor {
101− structure = Nothing,
102− rank = noRank,
103− flex = flex,
104− name = Just name,
105− copy = Nothing,
106− mark = noMark
100+namedVar flex name = UF.fresh $ Descriptor
101+ { structure = Nothing
102+ , rank = noRank
103+ , flex = flex
104+ , name = Just name
105+ , copy = Nothing
106+ , mark = noMark
107107 }
108108
109109var :: Flex -> IO Variable
110−var flex = UF.fresh $ Descriptor {
111− structure = Nothing,
112− rank = noRank,
113− flex = flex,
114− name = Nothing,
115− copy = Nothing,
116− mark = noMark
117− }
118−
119−structuredVar :: Term1 Variable -> IO Variable
120−structuredVar structure = UF.fresh $ Descriptor {
121− structure = Just structure,
122− rank = noRank,
123− flex = Flexible,
124− name = Nothing,
125− copy = Nothing,
126− mark = noMark
110+var flex = UF.fresh $ Descriptor
111+ { structure = Nothing
112+ , rank = noRank
113+ , flex = flex
114+ , name = Nothing
115+ , copy = Nothing
116+ , mark = noMark
127117 }
128118
129119
@@ -362,10 +352,23 @@ instance Crawl Descriptor where
362352
363353
364354toSrcType :: Variable -> IO T.CanonicalType
365−toSrcType variable = do
366− desc <- UF.descriptor =<< addNames variable
367− case structure desc of
368− Just term ->
355+toSrcType variable =
356+ do desc <- UF.descriptor =<< addNames variable
357+ srcType <- maybe (backupSrcType desc) termToSrcType (structure desc)
358+ return srcType
359+ where
360+ backupSrcType desc =
361+ case name desc of
362+ Just var@(Var.Canonical _ x@(c:_))
363+ | Char.isLower c -> return (T.Var x)
364+ | otherwise -> return $ T.Type var
365+
366+ _ -> error $ concat
367+ [ "Problem converting the following type "
368+ , "from a type-checker type to a source-syntax type:"
369+ , P.render (pretty Never variable) ]
370+
371+ termToSrcType term =
369372 case term of
370373 App1 a b -> do
371374 a' <- toSrcType a
@@ -389,16 +392,6 @@ toSrcType variable = do
389392 T.Var _ -> T.Record fields (Just ext')
390393 _ -> error "Used toSrcType on a type that is not well-formed"
391394
392− Nothing ->
393− case name desc of
394− Just var@(Var.Canonical _ x@(c:_))
395− | Char.isLower c -> return (T.Var x)
396− | otherwise -> return $ T.Type var
397−
398− _ -> error $ concat
399− [ "Problem converting the following type "
400− , "from a type-checker type to a source-syntax type:"
401− , P.render (pretty Never variable) ]
402395
403396data AppStructure = List Variable | Tuple [Variable] | Other
404397