module Top.Implementation.SimpleSubstitution where
import Top.Types
import Top.Implementation.General
import Top.Interface.Substitution
import Top.Interface.TypeInference
import Top.Interface.Basic
import Top.Monad.Select
import Top.Util.Embedding
import Top.Util.Empty
newtype SimpleState info = SimpleState { unSS :: MapSubstitution }
instance SolveState (SimpleState info) where
stateName _ = "Simple Substitution State"
instance Show (SimpleState info) where
show _ = "<Simple Substitution>"
instance Empty (SimpleState info) where
empty = SimpleState emptySubst
instance Embedded ClassSubst (SimpleState info) (SimpleState info) where embedding = idE
instance Embedded ClassSubst (Simple (SimpleState info) x m) (SimpleState info) where embedding = fromFstSimpleE embedding
instance ( MonadState s m
, HasBasic m info
, HasTI m info
, Embedded ClassSubst s (SimpleState info)
) =>
HasSubst (Select (SimpleState info) m) info where
makeSubstConsistent =
return ()
unifyTerms info t1 t2 =
do synonyms <- select getTypeSynonyms
t1' <- applySubst t1
t2' <- applySubst t2
case mguWithTypeSynonyms synonyms t1' t2' of
Right (_, sub) ->
modify (SimpleState . (sub @@) . unSS)
Left _ -> select (addLabeledError unificationErrorLabel info)
findSubstForVar i =
gets (lookupInt i . unSS)
fixpointSubst =
gets (FixpointSubstitution . unSS)