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 …