instance Num (Complex Rational) where (x:+y) + (x':+y') = (x+x') :+ (y+y') (x:+y) - (x':+y') = (x-x') :+ (y-y') (x:+y) * (x':+y') = (x*x'-y*y') :+ (x*y'+y*x') negate (x:+y) = negate x :+ negate y abs z = undefined signum z@(x:+y) = undefined fromInteger n = fromInteger n :+ 0
結果以下のようにそれは無理と怒られます 何かてはないでしようか?
Haskell Online Compiler [ghc-8.4.4] Copyright (c) The University of Glasgow
Compiling your program...
[1 of 1] Compiling Main ( prog.hs, prog.o )
prog.hs:7:10: error: • Illegal instance declaration for ‘Num (Complex Rational)’ (All instance types must be of the form (T a1 ... an) where a1 ... an are *distinct type variables*, and each type variable appears at most once in the instance head. Use FlexibleInstances if you want to disable this.) • In the instance declaration for ‘Num (Complex Rational)’ | 7 | instance Num (Complex Rational) where | ^^^^^^^^^^^^^^^^^^^^^^