How to resolve an issue with overloading operators in haskell? -
i can file compile fine. however, when try test if operator overloaded correctly error message:
*main> myfloat (2,3) + myfloat(3,3) <interactive>:19:15: ambiguous occurrence `+' refer either `main.+', defined @ problem1.hs:3:16 or `prelude.+', imported `prelude' @ problem1.hs:1:1 (and defined in `ghc.num')
the code using is:
data myfloat = myfloat (int, int) myfloat (a, b) + myfloat (c, d) = ((fromintegral a)/ (fromintegral(order a)) * 10^b) prelude.+ ((fromintegral c)/ (fromintegral(order c)) * 10^d) order :: int -> int order b | b == 0 = 0 | otherwise = ((ceiling ((logbase 10 (abs (fromintegral b))))) prelude.+ 1)
am misunderstanding how overload operators correctly, or there different problem entirely?
what want make class instance of num
instance num myfloat x + y = <put in definition here>
note num require definition of (*), abs, signum, frominteger, (negate | (-)) also
in haskell, 1 typically overloads functions using class definitions.
Comments
Post a Comment