{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE TypeSynonymInstances, OverlappingInstances #-}
import GHC.Float
class (Abs a) where
abs :: a -> Float
abs2 :: a -> Float
absEq :: a -> a -> Bool
instance (Abs Float) where
abs a = Prelude.abs (a)
abs2 a = a ** 2
absEq a b | Prelude.abs (a) == Prelude.abs (b) = True
| otherwise = False
instance (Abs Integer) where
abs a = fromIntegral (Prelude.abs(a))
abs2 a = fromIntegral (a * a)
absEq a b | Prelude.abs (a) == Prelude.abs (b) = True
| otherwise = False
instance (Abs a, Abs b) => Abs (a, b) where
abs (x, y) = sqrt $ Main.abs2(x,y)
abs2 (x, y) = Main.abs(x)**2 + Main.abs(y)**2
absEq (x, y) (w, z) | Main.abs(x,y) == Main.abs(w, z) = True
| otherwise = False
instance (Abs a) => Abs [a] where
abs (x:xs) = sqrt $ (Main.abs2(x)+Main.abs2(xs))
abs2 (x:xs) = Main.abs2(x)+Main.abs2(xs)
absEq x y | Main.abs (x) == Main.abs (y) = True
| otherwise = False
Использование {-# LANGUAGE UndecidableInstances #-} Haskell
Приветствую всех. Очень нужна помощь. Не могу разобраться зачем нужна UndecidableInstances. Могли бы вы помочь мне с этим. Особенно применимо к данной программе: