2017-11-08 15 views

答えて

3

はい。評価が必要なHaskell式を渡すのではなく、という数式を表すデータ型を作成する必要があります。たとえば、

data Formula = Term Int Int -- coefficient and exponent 
      | Sum Formula Formula deriving Show 

derive :: Formula -> Formula 
derive (Term coeff exp) = Term (coeff * exp) (exp - 1) 
derive (Sum x y) = Sum (derive x) (derive y) 

main = print (derive $ Sum (Term 1 2) (Term (-1) 1)) 
関連する問題