Commit 801c2637 authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

Fundeps work even for unary type classes

The functional-dependency improvement functions,
   improveFromAnother
   improveFromInstEnv
had a side-condition that said the type class has to have at
least two arguments.  But not so, as Trac #12763 shows:

   class C a | -> a where ...

is perfectly legal, albeit a bit of a corner case.
parent a182c0e8
...@@ -166,7 +166,7 @@ improveFromAnother :: loc ...@@ -166,7 +166,7 @@ improveFromAnother :: loc
improveFromAnother loc pred1 pred2 improveFromAnother loc pred1 pred2
| Just (cls1, tys1) <- getClassPredTys_maybe pred1 | Just (cls1, tys1) <- getClassPredTys_maybe pred1
, Just (cls2, tys2) <- getClassPredTys_maybe pred2 , Just (cls2, tys2) <- getClassPredTys_maybe pred2
, tys1 `lengthAtLeast` 2 && cls1 == cls2 , cls1 == cls2
= [ FDEqn { fd_qtvs = [], fd_eqs = eqs, fd_pred1 = pred1, fd_pred2 = pred2, fd_loc = loc } = [ FDEqn { fd_qtvs = [], fd_eqs = eqs, fd_pred1 = pred1, fd_pred2 = pred2, fd_loc = loc }
| let (cls_tvs, cls_fds) = classTvsFds cls1 | let (cls_tvs, cls_fds) = classTvsFds cls1
, fd <- cls_fds , fd <- cls_fds
...@@ -199,7 +199,6 @@ improveFromInstEnv _inst_env _ pred ...@@ -199,7 +199,6 @@ improveFromInstEnv _inst_env _ pred
= panic "improveFromInstEnv: not a class predicate" = panic "improveFromInstEnv: not a class predicate"
improveFromInstEnv inst_env mk_loc pred improveFromInstEnv inst_env mk_loc pred
| Just (cls, tys) <- getClassPredTys_maybe pred | Just (cls, tys) <- getClassPredTys_maybe pred
, tys `lengthAtLeast` 2
, let (cls_tvs, cls_fds) = classTvsFds cls , let (cls_tvs, cls_fds) = classTvsFds cls
instances = classInstances inst_env cls instances = classInstances inst_env cls
rough_tcs = roughMatchTcs tys rough_tcs = roughMatchTcs tys
......
{-# LANGUAGE FunctionalDependencies #-}
{-# OPTIONS_GHC -ddump-types #-}
module T12763 where
class C a | -> a where
m :: a -> ()
instance C Int where
m = undefined
-- Expecting inferred type f :: Int -> ()
f x = m x
TYPE SIGNATURES
f :: Int -> ()
m :: forall a. C a => a -> ()
TYPE CONSTRUCTORS
class C a | -> a where
m :: a -> ()
{-# MINIMAL m #-}
COERCION AXIOMS
axiom T12763.N:C :: C a = a -> () -- Defined at T12763.hs:6:1
INSTANCES
instance C Int -- Defined at T12763.hs:9:10
Dependent modules: []
Dependent packages: [base-4.9.0.0, ghc-prim-0.5.0.0,
integer-gmp-1.0.0.1]
...@@ -550,3 +550,4 @@ test('T12427b', normal, compile, ['']) ...@@ -550,3 +550,4 @@ test('T12427b', normal, compile, [''])
test('T12507', normal, compile, ['']) test('T12507', normal, compile, [''])
test('T12734', normal, compile, ['']) test('T12734', normal, compile, [''])
test('T12734a', normal, compile_fail, ['']) test('T12734a', normal, compile_fail, [''])
test('T12763', normal, compile, [''])
...@@ -8,21 +8,13 @@ T5684.hs:20:12: error: ...@@ -8,21 +8,13 @@ T5684.hs:20:12: error:
flop1 = [op False False, op 'c' undefined, op True undefined] flop1 = [op False False, op 'c' undefined, op True undefined]
T5684.hs:24:12: error: T5684.hs:24:12: error:
• No instance for (B Char b10) arising from a use of ‘op’ • No instance for (B Char b5) arising from a use of ‘op’
• In the expression: op 'c' undefined • In the expression: op 'c' undefined
In the expression: In the expression:
[op False False, op 'c' undefined, op True undefined] [op False False, op 'c' undefined, op True undefined]
In an equation for ‘flop1’: In an equation for ‘flop1’:
flop1 = [op False False, op 'c' undefined, op True undefined] flop1 = [op False False, op 'c' undefined, op True undefined]
T5684.hs:25:12: error:
• No instance for (A b11) arising from a use of ‘op’
• In the expression: op True undefined
In the expression:
[op False False, op 'c' undefined, op True undefined]
In an equation for ‘flop1’:
flop1 = [op False False, op 'c' undefined, op True undefined]
T5684.hs:29:12: error: T5684.hs:29:12: error:
• No instance for (A Bool) arising from a use of ‘op’ • No instance for (A Bool) arising from a use of ‘op’
• In the expression: op False False • In the expression: op False False
...@@ -31,16 +23,8 @@ T5684.hs:29:12: error: ...@@ -31,16 +23,8 @@ T5684.hs:29:12: error:
In an equation for ‘flop2’: In an equation for ‘flop2’:
flop2 = [op False False, op True undefined, op 'c' undefined] flop2 = [op False False, op True undefined, op 'c' undefined]
T5684.hs:30:12: error:
• No instance for (A b8) arising from a use of ‘op’
• In the expression: op True undefined
In the expression:
[op False False, op True undefined, op 'c' undefined]
In an equation for ‘flop2’:
flop2 = [op False False, op True undefined, op 'c' undefined]
T5684.hs:31:12: error: T5684.hs:31:12: error:
• No instance for (B Char b9) arising from a use of ‘op’ • No instance for (B Char b4) arising from a use of ‘op’
• In the expression: op 'c' undefined • In the expression: op 'c' undefined
In the expression: In the expression:
[op False False, op True undefined, op 'c' undefined] [op False False, op True undefined, op 'c' undefined]
...@@ -48,21 +32,13 @@ T5684.hs:31:12: error: ...@@ -48,21 +32,13 @@ T5684.hs:31:12: error:
flop2 = [op False False, op True undefined, op 'c' undefined] flop2 = [op False False, op True undefined, op 'c' undefined]
T5684.hs:35:12: error: T5684.hs:35:12: error:
• No instance for (B Char b6) arising from a use of ‘op’ • No instance for (B Char b3) arising from a use of ‘op’
• In the expression: op 'c' undefined • In the expression: op 'c' undefined
In the expression: In the expression:
[op 'c' undefined, op True undefined, op False False] [op 'c' undefined, op True undefined, op False False]
In an equation for ‘flop3’: In an equation for ‘flop3’:
flop3 = [op 'c' undefined, op True undefined, op False False] flop3 = [op 'c' undefined, op True undefined, op False False]
T5684.hs:36:12: error:
• No instance for (A b7) arising from a use of ‘op’
• In the expression: op True undefined
In the expression:
[op 'c' undefined, op True undefined, op False False]
In an equation for ‘flop3’:
flop3 = [op 'c' undefined, op True undefined, op False False]
T5684.hs:37:12: error: T5684.hs:37:12: error:
• No instance for (A Bool) arising from a use of ‘op’ • No instance for (A Bool) arising from a use of ‘op’
• In the expression: op False False • In the expression: op False False
...@@ -72,7 +48,7 @@ T5684.hs:37:12: error: ...@@ -72,7 +48,7 @@ T5684.hs:37:12: error:
flop3 = [op 'c' undefined, op True undefined, op False False] flop3 = [op 'c' undefined, op True undefined, op False False]
T5684.hs:40:12: error: T5684.hs:40:12: error:
• No instance for (B Char b4) arising from a use of ‘op’ • No instance for (B Char b2) arising from a use of ‘op’
• In the expression: op 'c' undefined • In the expression: op 'c' undefined
In the expression: In the expression:
[op 'c' undefined, op False False, op True undefined] [op 'c' undefined, op False False, op True undefined]
...@@ -87,24 +63,8 @@ T5684.hs:41:12: error: ...@@ -87,24 +63,8 @@ T5684.hs:41:12: error:
In an equation for ‘flop4’: In an equation for ‘flop4’:
flop4 = [op 'c' undefined, op False False, op True undefined] flop4 = [op 'c' undefined, op False False, op True undefined]
T5684.hs:42:12: error:
• No instance for (A b5) arising from a use of ‘op’
• In the expression: op True undefined
In the expression:
[op 'c' undefined, op False False, op True undefined]
In an equation for ‘flop4’:
flop4 = [op 'c' undefined, op False False, op True undefined]
T5684.hs:46:12: error:
• No instance for (A b3) arising from a use of ‘op’
• In the expression: op True undefined
In the expression:
[op True undefined, op 'c' undefined, op False False]
In an equation for ‘flop5’:
flop5 = [op True undefined, op 'c' undefined, op False False]
T5684.hs:47:12: error: T5684.hs:47:12: error:
• No instance for (B Char b2) arising from a use of ‘op’ • No instance for (B Char b1) arising from a use of ‘op’
• In the expression: op 'c' undefined • In the expression: op 'c' undefined
In the expression: In the expression:
[op True undefined, op 'c' undefined, op False False] [op True undefined, op 'c' undefined, op False False]
...@@ -119,14 +79,6 @@ T5684.hs:48:12: error: ...@@ -119,14 +79,6 @@ T5684.hs:48:12: error:
In an equation for ‘flop5’: In an equation for ‘flop5’:
flop5 = [op True undefined, op 'c' undefined, op False False] flop5 = [op True undefined, op 'c' undefined, op False False]
T5684.hs:52:12: error:
• No instance for (A b0) arising from a use of ‘op’
• In the expression: op True undefined
In the expression:
[op True undefined, op False False, op 'c' undefined]
In an equation for ‘flop6’:
flop6 = [op True undefined, op False False, op 'c' undefined]
T5684.hs:53:12: error: T5684.hs:53:12: error:
• No instance for (A Bool) arising from a use of ‘op’ • No instance for (A Bool) arising from a use of ‘op’
• In the expression: op False False • In the expression: op False False
...@@ -136,7 +88,7 @@ T5684.hs:53:12: error: ...@@ -136,7 +88,7 @@ T5684.hs:53:12: error:
flop6 = [op True undefined, op False False, op 'c' undefined] flop6 = [op True undefined, op False False, op 'c' undefined]
T5684.hs:54:12: error: T5684.hs:54:12: error:
• No instance for (B Char b1) arising from a use of ‘op’ • No instance for (B Char b0) arising from a use of ‘op’
• In the expression: op 'c' undefined • In the expression: op 'c' undefined
In the expression: In the expression:
[op True undefined, op False False, op 'c' undefined] [op True undefined, op False False, op 'c' undefined]
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment