
2007/7/9, lassoken
Hi,
I'm trying to translate Example 2.3.3 (simple symbolic differentation) from Structure and Interpretation of Computer Programs into Haskell.
Here is code that works (as far as see): --- data Term b = Var String | Const b | Sum (Term b) (Term b) | Prod (Term b) (Term b) ... --instance Show (Term b) where show = showTerm showTerm (Var x) = x showTerm (Const c) = show c showTerm (Sum a b) = "(" ++ showTerm a ++ "+" ++ showTerm b ++ ")" showTerm (Prod a b) = "(" ++ showTerm a ++ showTerm b ++ ")" ---
Where should I put type constraint (Show b) to be able to define Term b as an instance of Show class?
Actually, I would like to say that Term b is an instance of Show iff b is and not to put constraint on b.
instance Show b => Show (Term b) where ... I believe it is in the Gentle introduction to Haskell.