# 021: infixl_add_mul2.hs で演算子の優先順位が不適切 [↑up](bunny_notes) - issued: 2020-04-13 - 分類: A サンプルコードが fail - status: Closed (2020-04-13) ## 現象 以下のコードをコンパイル、実行すると、結果が 20 になる: infixl_add_mul2.hs: $$
{
x :: Integer
x = 2 + 3 * 4
main = print x
$$}
## 調査ログ
### 2020-04-13
lib/Prelude.hs に四則演算についての infixl 宣言を追加して解決。
$${
diff --git a/compiler/lib/Prelude.hs b/compiler/lib/Prelude.hs
index 67675ea..c326a8d 100644
--- a/compiler/lib/Prelude.hs
+++ b/compiler/lib/Prelude.hs
@@ -3,6 +3,9 @@ module Prelude where
-- Qualified name of (:) is (Prim.:)
-- infixr 5 :
+infixl 7 *, /, `quot`, `rem`, `div`, `mod`
+infixl 6 +, -
+
infixl 1 >>, >>=
class Monad m where
$$}