@@ -1,4 +1,3 @@
1−{-# LANGUAGE MultiWayIf #-}
2module Type.State where
1module Type.State where
4import Type.Type
3import Type.Type
@@ -128,49 +127,49 @@ makeInstance var = do
128makeCopy :: Int -> Variable -> StateT SolverState IO Variable
127makeCopy :: Int -> Variable -> StateT SolverState IO Variable
129makeCopy alreadyCopied variable = do
128makeCopy alreadyCopied variable = do
130 desc <- liftIO $ UF.descriptor variable
129 desc <- liftIO $ UF.descriptor variable
131− if | mark desc == alreadyCopied ->
131+ () | mark desc == alreadyCopied ->
132 case copy desc of
132 case copy desc of
133 Just v -> return v
133 Just v -> return v
134 Nothing -> error "This should be impossible."
134 Nothing -> error "This should be impossible."
136− | rank desc /= noRank || flex desc == Constant ->
136+ | rank desc /= noRank || flex desc == Constant ->
137 return variable
137 return variable
139− | otherwise -> do
139+ | otherwise -> do
140− pool <- getPool
140+ pool <- getPool
141− newVar <- liftIO $ UF.fresh $ Descriptor {
141+ newVar <- liftIO $ UF.fresh $ Descriptor {
142− structure = Nothing,
142+ structure = Nothing,
143− rank = maxRank pool,
143+ rank = maxRank pool,
144− mark = noMark,
144+ mark = noMark,
145− flex = case flex desc of
145+ flex = case flex desc of
146− Is s -> Is s
146+ Is s -> Is s
147− _ -> Flexible,
147+ _ -> Flexible,
148− copy = Nothing,
148+ copy = Nothing,
149− name = case flex desc of
149+ name = case flex desc of
150− Rigid -> Nothing
150+ Rigid -> Nothing
151− _ -> name desc
151+ _ -> name desc
154− register newVar
153+ register newVar
156− -- Link the original variable to the new variable. This lets us
155+ -- Link the original variable to the new variable. This lets us
157− -- avoid making multiple copies of the variable we are instantiating.
156+ -- avoid making multiple copies of the variable we are instantiating.
159− -- Need to do this before recursively copying the structure of
158+ -- Need to do this before recursively copying the structure of
160− -- the variable to avoid looping on cyclic terms.
159+ -- the variable to avoid looping on cyclic terms.
161− liftIO $ UF.modifyDescriptor variable $ \desc ->
160+ liftIO $ UF.modifyDescriptor variable $ \desc ->
162− desc { mark = alreadyCopied, copy = Just newVar }
161+ desc { mark = alreadyCopied, copy = Just newVar }
164− -- Now we recursively copy the structure of the variable.
163+ -- Now we recursively copy the structure of the variable.
165− -- We have already marked the variable as copied, so we
164+ -- We have already marked the variable as copied, so we
166− -- will not repeat this work or crawl this variable again.
165+ -- will not repeat this work or crawl this variable again.
167− case structure desc of
166+ case structure desc of
168− Nothing -> return newVar
167+ Nothing -> return newVar
169− Just term -> do
168+ Just term -> do
170− newTerm <- traverseTerm (makeCopy alreadyCopied) term
169+ newTerm <- traverseTerm (makeCopy alreadyCopied) term
171− liftIO $ UF.modifyDescriptor newVar $ \desc ->
170+ liftIO $ UF.modifyDescriptor newVar $ \desc ->
172− desc { structure = Just newTerm }
171+ desc { structure = Just newTerm }
173− return newVar
172+ return newVar
175restore :: Int -> Variable -> StateT SolverState IO Variable
174restore :: Int -> Variable -> StateT SolverState IO Variable
176restore alreadyCopied variable = do
175restore alreadyCopied variable = do