関数型プログラミング言語Haskell Part7
■ このスレッドは過去ログ倉庫に格納されています
0828819
2007/08/26(日) 15:34:26haskellは演算子を定義できるそうですが、Pointに+を定義しようとしたらコンパイルエラーになりました。
どうも、数値の+とかぶっているから駄目ぽいのですが回避する方法はあるでしょうか。
なお演算子を+++にしたら動きましたが、見た目がダサいので何とか+を使いたいです。
============ソース===========
data Point = Point_new { x :: Int , y :: Int }
deriving ( Show )
(+) :: Point -> Point -> Point
a + b = Point_new ((x a)+(x b)) ((y a)+(y b))
main = putStrLn $ show $ ((Point_new 3 4 ) + (Point_new 5 7))
=============コンパイルエラー==================
test.hs:5:24:
Ambiguous occurrence `+'
It could refer to either `+', defined at test.hs:5:2
or `+', imported from Prelude
test.hs:5:38:
Ambiguous occurrence `+'
It could refer to either `+', defined at test.hs:5:2
or `+', imported from Prelude
test.hs:7:43:
Ambiguous occurrence `+'
It could refer to either `+', defined at test.hs:5:2
or `+', imported from Prelude
■ このスレッドは過去ログ倉庫に格納されています