単純化された問題
与えられた
class Foo f where
frobnicate :: f -> Float
どうすれば許可できますinstanceかFoo
data Bar = Bar { <here> }
?
実際の問題
与えられた
-- Typically lightweight geometric objects, e.g. spheres
class Shape s where
intersect :: (RealFrac t, Floating t, Ord t, Shape s)
=> Ray t -> s t -> Maybe (DifferentialGeometry t)
と
-- Primitives contain higher level informations, like material properties
class Primitive p where
intersect :: (RealFrac t, Floating t, Ord t, Primitive p)
=> Ray t -> p t -> Maybe (Intersection t)
Primitive.intersectとのシグネチャの唯一の違いはShape.intersect、戻り値の型にあることに注意してください。
Shapeここで、基本的に anyをに変換するラッパーを追加したいと思いますPrimitive。
おおよそ次のように機能すると思います。
data ShapeWrapperPrimitive t = ShapeWrapperPrimitive {
shape :: (Shape s) => s t
}
つまり、クラスの任意shapeのメンバーを追加したいと思います。Shape
しかし、これは私に与えますIllegal polymorphic or qualified type。