Haskell の一般的な計算を型レベルで表現するための適切な慣用的な方法が存在する必要があります。私が思いつくことができるのは、この(違法な)オブジェクト指向の模倣だけです。
class Computation where
compute :: Computation -> Double -> Double
data Id = Id
instance Computation Id where
compute _ = id
data Square a = Computation a => Square a
instance Computation (Square a) where
compute (Square underlying) x = sqr $ compute underlying x where square x = x*x
data Scale a = Computation a => Scale a Double
compute (Scale underlying c) x = c * compute underlying x
理想的には、私は開放性を維持したいので、このアプローチは私には魅力的ではありません. 求めすぎですか?