@@ -75,14 +75,14 @@ a ==> b = TermN (Fun1 a b)
76f <| a = TermN (App1 f a)
76f <| a = TermN (App1 f a)
78−data Descriptor = Descriptor {
78+data Descriptor = Descriptor
79− structure :: Maybe (Term1 Variable),
79+ { structure :: Maybe (Term1 Variable)
80− rank :: Int,
80+ , rank :: Int
81− flex :: Flex,
81+ , flex :: Flex
82− name :: Maybe TypeName,
82+ , name :: Maybe TypeName
83− copy :: Maybe Variable,
83+ , copy :: Maybe Variable
84− mark :: Int
84+ , mark :: Int
85−} deriving Show
85+ } deriving Show
87noRank = -1
87noRank = -1
88outermostRank = 0 :: Int
88outermostRank = 0 :: Int
@@ -97,33 +97,23 @@ data SuperType = Number | Comparable | Appendable
97 deriving (Show, Eq)
97 deriving (Show, Eq)
99namedVar :: Flex -> Var.Canonical -> IO Variable
99namedVar :: Flex -> Var.Canonical -> IO Variable
100−namedVar flex name = UF.fresh $ Descriptor {
100+namedVar flex name = UF.fresh $ Descriptor
101− structure = Nothing,
101+ { structure = Nothing
102− rank = noRank,
102+ , rank = noRank
103− flex = flex,
103+ , flex = flex
104− name = Just name,
104+ , name = Just name
105− copy = Nothing,
105+ , copy = Nothing
106− mark = noMark
106+ , mark = noMark
109var :: Flex -> IO Variable
109var :: Flex -> IO Variable
110−var flex = UF.fresh $ Descriptor {
110+var flex = UF.fresh $ Descriptor
111− structure = Nothing,
111+ { structure = Nothing
112− rank = noRank,
112+ , rank = noRank
113− flex = flex,
113+ , flex = flex
114− name = Nothing,
114+ , name = Nothing
115− copy = Nothing,
115+ , copy = Nothing
119−structuredVar :: Term1 Variable -> IO Variable
120−structuredVar structure = UF.fresh $ Descriptor {
121− structure = Just structure,
126− mark = noMark
116+ , mark = noMark
@@ -362,10 +352,23 @@ instance Crawl Descriptor where
364toSrcType :: Variable -> IO T.CanonicalType
354toSrcType :: Variable -> IO T.CanonicalType
365−toSrcType variable = do
355+toSrcType variable =
366− desc <- UF.descriptor =<< addNames variable
356+ do desc <- UF.descriptor =<< addNames variable
367− case structure desc of
357+ srcType <- maybe (backupSrcType desc) termToSrcType (structure desc)
368− Just term ->
358+ return srcType
360+ backupSrcType desc =
362+ Just var@(Var.Canonical _ x@(c:_))
363+ | Char.isLower c -> return (T.Var x)
364+ | otherwise -> return $ T.Type var
367+ [ "Problem converting the following type "
368+ , "from a type-checker type to a source-syntax type:"
369+ , P.render (pretty Never variable) ]
371+ termToSrcType term =
369 case term of
372 case term of
370 App1 a b -> do
373 App1 a b -> do
371 a' <- toSrcType a
374 a' <- toSrcType a
@@ -389,16 +392,6 @@ toSrcType variable = do
389 T.Var _ -> T.Record fields (Just ext')
392 T.Var _ -> T.Record fields (Just ext')
390 _ -> error "Used toSrcType on a type that is not well-formed"
393 _ -> error "Used toSrcType on a type that is not well-formed"
394− Just var@(Var.Canonical _ x@(c:_))
395− | Char.isLower c -> return (T.Var x)
396− | otherwise -> return $ T.Type var
399− [ "Problem converting the following type "
400− , "from a type-checker type to a source-syntax type:"
401− , P.render (pretty Never variable) ]
403data AppStructure = List Variable | Tuple [Variable] | Other
396data AppStructure = List Variable | Tuple [Variable] | Other