You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
summary: Multiple default declarations are not allowed
4
+
severity: error
5
+
introduced: 9.6.1
6
+
---
7
+
8
+
A numeric literal such as `5` is overloaded in Haskell and has the type `forall a. Num a => a`.
9
+
This allows the programmer to use numeric literals in many contexts without having a separate literal syntax for different numeric types.
10
+
By extension, many numeric functions have a polymorphic type involving the `Num` type class.
11
+
12
+
A downside of using overloaded arithmetic expressions is that GHC is not always able to non-ambiguously infer a concrete type, such as `Int` or `Double`.
13
+
This is the case, for example, in the expression `show 5`.
14
+
The compiler cannot infer if the programmer means `show (5 :: Int)`, `show (5 :: Double)` or any other numeric type.
15
+
16
+
Since this case is very common, the Haskell report specifies a default behaviour for overloaded numeric expressions which involve the `Num` typeclass.
17
+
Numeric types are defaulted to `Integer`, and if that is not possible to `Double`.
18
+
19
+
This defaulting behaviour can be customized with "default declarations".
20
+
A default declaration uses the syntax `default (...)` with a list of comma-separated types.
21
+
These types are tried in the order in which they occur in the default declaration.
22
+
However, every Haskell module may contain at most one such default declaration.
23
+
If a module contains more that one default declaration, then this error is thrown by GHC.
0 commit comments