我只是建议currying和hylomorphism。
data TypeF a
= TypeApplication a a
| TypeVariable Name
deriving (Read,Show,Eq,Functor,Foldable,Traversable)
type Type = Fix TypeF
unify :: (Type, Type) -> Result
unify = hylo algebra coalgebra
where algebra :: TypeF Result -> Result
algebra = ...
coalgebra :: (Type, Type) -> TypeF (Type, Type)
coalgebra = ...
顺便说一句,我可能会TypeF
使用递归方案包如下。
import Data.Functor.Foldable.TH (makeBaseFunctor)
data Type = TypeApplication Type Type
| TypeVariable Name
makeBaseFunctor ''Type
在这种情况下,这将自动生成您想要的内容,而无需使用 to Fix
。