[表示 : 全て 最新50 1-99 101- 201- 301- 401- 501- 601- 701- 801- 901- 1001- 2ch.scのread.cgiへ]
Update time : 10/10 00:15 / Filesize : 342 KB / Number-of Response : 1029
[このスレッドの書き込みを削除する]
[+板 最近立ったスレ&熱いスレ一覧 : +板 最近立ったスレ/記者別一覧] [類似スレッド一覧]


↑キャッシュ検索、類似スレ動作を修正しました、ご迷惑をお掛けしました

関数型プログラミング言語Haskell Part33



460 名前:デフォルトの名無しさん mailto:sage [2020/08/31(月) 00:20:32.36 ID:XlY0VH6O.net]
Complex RationalにNumのinstance宣言できないかと思って以下のようにしてみました

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
| ^^^^^^^^^^^^^^^^^^^^^^






[ 続きを読む ] / [ 携帯版 ]

全部読む 前100 次100 最新50 [ このスレをブックマーク! 携帯に送る ] 2chのread.cgiへ
[+板 最近立ったスレ&熱いスレ一覧 : +板 最近立ったスレ/記者別一覧](;´∀`)<342KB

read.cgi ver5.27 [feat.BBS2 +1.6] / e.0.2 (02/09/03) / eucaly.net products.
担当:undef