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

Popular posts from this blog

java - Run spring boot application error: Cannot instantiate interface org.springframework.context.ApplicationListener -

reactjs - React router and this.props.children - how to pass state to this.props.children -

Excel VBA "Microsoft Windows Common Controls 6.0 (SP6)" Location Changes -