1
使用Haskell类型类强制交换
我想为可以交叉在一起的几何对象定义一个类型类: class Intersect a b c | a b -> c where intersect :: a -> b -> c -- Language extensions: -XMultiParamTypeClasses, -XFunctionalDependencies 这个想法是要有一个通用的交集函数,可以处理不同类型的对象。可以想象这样的情况 instance Intersect Line Plane (Maybe Point) where ... instance Intersect Plane Plane (Maybe Line) where ... 但我也想声明交集是可交换的: instance (Intersect a b c) => Intersect b …