I'm still new to Haskell, and I have this piece of code, but ghc does not compile and does not give me an error.
This is the code:
data QT a = C a | Q (QT a) (QT a) (QT a) (QT a) deriving (Show)
moltiply :: QT a -> Int -> QT a
moltiply (C a) x = (C (a * x))
moltiply (Q a b c d) x = Q (moltiply a x) (moltiply b x) (moltiply c x) (moltiply d x)
And this is the error I get:
Couldn't match expected type āaā with actual type āIntā
āaā is a rigid type variable bound by
the type signature for multiply :: QT a -> Int -> QT a
at file.hs:12:15
Relevant bindings include
a :: a (bound at file.hs:13:15)
multiply :: QT a -> Int -> QT a
(bound at file.hs:13:1)
In the second argument of ā(*)ā, namely āxā
In the first argument of āCā, namely ā(a * x)ā
source
share