I'm a newbie in the Haskell's world, so this may be a basic question.
Could this code:
data Numero =
Integer Integer |
Rational Rational |
Double Double
deriving (Show)
data Elemento =
Numero Numero |
Incognita String
deriving (Show)
data Monomio = Monomio {base :: Elemento, exp :: Numero} deriving(Show)
main = print (Monomio (Numero (Integer 15)) (Integer 20))
be expressed without the explicit types at:
(Monomio (Numero (Integer 15)) (Integer 20))
?
This expression:
main = print (Monomio (Integer 15) (Integer 20))
which is shorter is not ambiguous, as (Integer 15) can't fit the definition of (Incognita String), but it doesn't compile:
main.hs:13:24:
Couldn't match expected type `Elemento' with actual type `Numero'
In the first argument of `Monomio', namely `(Integer 15)'
In the first argument of `print', namely
`(Monomio (Integer 15) (Integer 20))'
Why?