I am new to Haskell and was trying to create a class with an instance.
I have the following code and I am trying to say that: 1) Branch can hold any type in its first position, 2) Make a class Linear which takes the linear thing and returns a number 3) Make Branch an instance of Linear if the first thing the Branch holds is something that is part of the Num class.
data Branch a = Branch a Integer deriving (Show, Eq)
class Linear l where
length :: (Num a) => l -> a
instance (Num a) => Linear (Branch a) where
length (Branch len _) = len
I get the error: Could not deduce (a ~ a1) from the context (Num a) bound by the instance declaration at.....
Does anybody know how to express in Haskell what it is I'm trying to say?