File tree Expand file tree Collapse file tree 4 files changed +92
-0
lines changed
message-index/messages/GHC-25897 Expand file tree Collapse file tree 4 files changed +92
-0
lines changed Original file line number Diff line number Diff line change
1
+ {-# LANGUAGE LambdaCase #-}
2
+ {-# LANGUAGE DataKinds #-}
3
+ {-# LANGUAGE GADTs #-}
4
+ {-# LANGUAGE TypeFamilies #-}
5
+
6
+ module Example1 where
7
+
8
+ data X = A | B
9
+
10
+ data F x where
11
+ FA :: F A
12
+ FB :: F B
13
+
14
+ -- Compiles successfully, because the
15
+ -- result type of the pattern match
16
+ -- is known, from the type signature,
17
+ -- to be 'Bool'.
18
+ foo2 :: F x -> Bool
19
+ foo2 = \ case
20
+ FA -> True
21
+ FB -> False
22
+
23
+ type family G a where
24
+ G A = Bool
25
+ G B = Bool
26
+
27
+ -- Compiles successfully, because the
28
+ -- result type of the pattern match
29
+ -- is known, from the type signature,
30
+ -- to be 'G x'
31
+ foo3 :: F x -> G x
32
+ foo3 = \ case
33
+ FA -> True
34
+ FB -> False
Original file line number Diff line number Diff line change
1
+ {-# LANGUAGE LambdaCase #-}
2
+ {-# LANGUAGE DataKinds #-}
3
+ {-# LANGUAGE GADTs #-}
4
+ {-# LANGUAGE TypeFamilies #-}
5
+
6
+ module Example1 where
7
+
8
+ data X = A | B
9
+
10
+ data F x where
11
+ FA :: F A
12
+ FB :: F B
13
+
14
+ -- Results in error GHC-25897
15
+ foo1 = \ case
16
+ FA -> True
17
+ FB -> False
Original file line number Diff line number Diff line change
1
+ ---
2
+ title : A pattern match, without known return type, on a GADT
3
+ ---
Original file line number Diff line number Diff line change
1
+ ---
2
+ title : GADT pattern match must have a known result type
3
+ summary : A pattern match on a GADT cannot succeed unless GHC knows the result type of the pattern match.
4
+ severity : error
5
+ introduced : 9.6.1
6
+ ---
7
+
8
+ A pattern match on a GADT cannot succeed unless GHC knows the result
9
+ type of the pattern match. This information might, for example, be derived from a type
10
+ signature, or by type inference due to the context in which the pattern match occurs.
11
+
12
+ To solve the problem you must somehow tell GHC the type of the pattern
13
+ match. For example, in the below error message GHC suggests giving
14
+ the pattern match a type signature.
15
+
16
+ ```
17
+ example1.hs:14:9: error: [GHC-25897]
18
+ • Could not deduce ‘p ~ Bool’
19
+ from the context: x ~ A
20
+ bound by a pattern with constructor: FA :: F A,
21
+ in a \case alternative
22
+ at test17.hs:14:3-4
23
+ ‘p’ is a rigid type variable bound by
24
+ the inferred type of foo1 :: F x -> p
25
+ at test17.hs:(13,1)-(15,13)
26
+ • In the expression: True
27
+ In a \case alternative: FA -> True
28
+ In the expression:
29
+ \case
30
+ FA -> True
31
+ FB -> False
32
+ • Relevant bindings include
33
+ foo1 :: F x -> p (bound at test17.hs:13:1)
34
+ Suggested fix: Consider giving ‘foo1’ a type signature
35
+ |
36
+ 14 | FA -> True
37
+ | ^^^^
38
+ ```
You can’t perform that action at this time.
0 commit comments