File tree Expand file tree Collapse file tree 4 files changed +93
-0
lines changed
message-index/messages/GHC-25897 Expand file tree Collapse file tree 4 files changed +93
-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, for example because the pattern match has a
10
+ type signature, or because the type of the pattern match can be
11
+ inferred from its context.
12
+
13
+ To solve the problem you must somehow tell GHC the type of the pattern
14
+ match. For example, in the below error message GHC suggests giving
15
+ the pattern match a type signature.
16
+
17
+ ```
18
+ example1.hs:14:9: error: [GHC-25897]
19
+ • Could not deduce ‘p ~ Bool’
20
+ from the context: x ~ A
21
+ bound by a pattern with constructor: FA :: F A,
22
+ in a \case alternative
23
+ at test17.hs:14:3-4
24
+ ‘p’ is a rigid type variable bound by
25
+ the inferred type of foo1 :: F x -> p
26
+ at test17.hs:(13,1)-(15,13)
27
+ • In the expression: True
28
+ In a \case alternative: FA -> True
29
+ In the expression:
30
+ \case
31
+ FA -> True
32
+ FB -> False
33
+ • Relevant bindings include
34
+ foo1 :: F x -> p (bound at test17.hs:13:1)
35
+ Suggested fix: Consider giving ‘foo1’ a type signature
36
+ |
37
+ 14 | FA -> True
38
+ | ^^^^
39
+ ```
You can’t perform that action at this time.
0 commit comments