Error - Unresolved Overloading
Re: New to haskell: unresolved overloading question Messages sorted by: [ date ] [ thread ] [ subject ] [ author ] Am Montag, 21. Februar 2005 17:32 schrieb Christian Maeder: > Blair Fraser wrote: > > I'm new to haskell and I'm working through the class section of the > > gentle tutorial. I decided to implement an ApproxEq class (just for > > fun), but have run into problems. The code below works fine for units > > and bools, but gives an unresolved overloading error for Floats and > > Doubles. What's going on here? What does the error message mean and > > what did I do wrong? (I'm in Hugs.) > > > > -- ApproxEq: My first class. > > class (Eq a) => ApproxEq a where > > (~=) :: a -> a -> Bool > > x ~= y = x == y -- By default, check equality > > > > -- These two override default with same, just checking if it works > > instance ApproxEq () where () ~= () = True > > instance ApproxEq Bool where x ~= y = x == y > > > > -- These two override default with different > > -- consider floating points equal if they differ by one or less > > instance ApproxEq Float where x ~= y = (abs (x-y) <= 1) > > instance ApproxEq Double where x ~= y = (abs (x-y) <= 1) > > More elegant seems to be: > > instance (Ord a, Num a) => ApproxEq a where x ~= y = (abs (x-y) < 1) > > However, this requires extensions to "Allow unsafe overlapping instances": > > hugs -98 +O > > ghci -fglasgow-exts -fallow-overlapping-instances > -fallow-undecidable-instances -fallow-incoherent-instances > > > -- This one dosn't work either, but it just depends on the other two > > instance ApproxEq a => ApproxEq [a] where > > [] ~= [] = True > > (x:xs) ~= (y:ys) = x ~= y && xs ~= ys > > _ ~= _ = False > > > > Thanks, > > Blair > For the original code, no extensions are necessary (and neither hugs nor ghc does complain). Probably something like ApproxEq> 1.5 ~= 2.4 ERROR - Unresolved overloading *** Type : (Fr
von GoogleAnmeldenAusgeblendete FelderNach Gruppen oder Nachrichten suchen
uni-bielefeld https://marc.info/?l=haskell&m=120492259108784&w=4 ! de [Download message RAW] David Scarlett wrote: > > Can anyone shed some light on the https://forum.qt.io/topic/61313/unresolved-overloaded-function-type-error following error? Thanks in advance. > > isSorted :: Ord a => [a] -> Bool > error - isSorted [] = True > isSorted [x] = True > isSorted (x1:x2:xs) > | x1 <= x2 = isSorted (x2:xs) > | otherwise = False > > -------- [...] > Main> isSorted [] > error - unresolved ERROR: Unresolved overloading > *** Type : Ord a => Bool > *** Expression : isSorted [] > -------- The list constructor [] is overloaded, so it's type cannot be infered inambigously. The empty list can be of any list type, HUGS cannot check if it's parameter's type is an instance of Ord. -- Ralf Krueger E-Mail: rkrueger@TechFak.Uni-Bielefeld.DE URL: http://www.Ralf-Krueger.DE Bielefeld University Center for Interdisciplinary Research (ZiF) WWW Administration Wellenberg 1 33615 Bielefeld Germany Tel: ++49 521 106-2777 [prev in list] [next in list] [prev in thread] [next in thread] Configure | About | News | Addalist | SponsoredbyKoreLogic
download a browser that supports JavaScript, or enable it if it's disabled (i.e. NoScript). Home Qt Development General and Desktop unresolved overloaded function type error unresolved overloaded function type error This topic has been deleted. Only users with topic management privileges can see it. zeroptr last edited by Hi All, I have this error after I wrote the code frmmain.cpp:78: error: no match for 'operator==' (operand types are '