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