Commit bdc2e98e authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

Tests for functional dependencies and loops in TcSimplify

parent bf9817ea
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}
{-# LANGUAGE FlexibleInstances, FlexibleContexts #-}
-- Trac #1781
-- This one should really succeed, because 'plus' can only
-- be called with a = Int->Int, but the old fundep story
-- certainly made it fail, and so that's what we expect for now
-- We may become more liberal later
module ShouldCompile where
class E a b | a -> b, b -> a
instance E a a
plus :: (E a (Int -> Int)) => Int -> a
plus x y = x + y
FD1.hs:12:0:
Couldn't match expected type `a' against inferred type `Int -> Int'
`a' is a rigid type variable bound by
the type signature for `plus' at FD1.hs:11:11
The equation(s) for `plus' have two arguments,
which does not match its type
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies #-}
{-# LANGUAGE PatternSignatures, ScopedTypeVariables, FlexibleContexts #-}
-- Trac #1783
-- Like Trac #1781 you could argue that this one should succeed
-- but we stick with the old behaviour for now. When we do
-- fundeps properly it'll probably start to work
module ShouldCompile where
import Prelude hiding (foldr, foldr1)
import Data.Maybe
class Elem a e | a -> e
class Foldable a where
foldr :: Elem a e => (e -> b -> b) -> b -> a -> b
-- foldr1 :: forall e. Elem a e => (e -> e -> e) -> a -> e -- WORKS!
foldr1 :: Elem a e => (e -> e -> e) -> a -> e
foldr1 f xs = fromMaybe (error "foldr1: empty structure")
(foldr mf Nothing xs)
where mf :: Elem a e => (e -> Maybe e -> Maybe e)
mf x Nothing = Just x
mf x (Just y) = Just (f x y)
FD2.hs:26:35:
Couldn't match expected type `e' against inferred type `e1'
`e' is a rigid type variable bound by
the type signature for `foldr1' at FD2.hs:21:19
`e1' is a rigid type variable bound by
the type signature for `mf' at FD2.hs:24:24
In the first argument of `f', namely `x'
In the first argument of `Just', namely `(f x y)'
In the expression: Just (f x y)
{-# LANGUAGE MultiParamTypeClasses, FunctionalDependencies, FlexibleInstances #-}
-- Trac #1795
-- This should fail. It used to fail saying it can't unify
-- 'a' with '(String, a)'
-- but now it simply says that it can't deduce
-- (MkA (String, a) a) from the context ()
-- which is fair enough
module ShouldCompile where
data A a = A
class MkA a b | a -> b where
mkA :: a -> A b
instance MkA a a where
translate :: (String, a) -> A a
translate a = mkA a
FD3.hs:22:14:
Could not deduce (MkA (String, a) a) from the context ()
arising from a use of `mkA' at FD3.hs:22:14-18
Possible fix:
add (MkA (String, a) a) to the context of
the type signature for `translate'
or add an instance declaration for (MkA (String, a) a)
In the expression: mkA a
In the definition of `translate': translate a = mkA a
{-# LANGUAGE
MultiParamTypeClasses,
FunctionalDependencies,
UndecidableInstances,
OverlappingInstances,
FlexibleInstances,
EmptyDataDecls #-}
-- Trac #1797
module ShouldCompile where
data True
data False
class TypeEq type1 type2 result | type1 type2 -> result where
typeEq :: type1 -> type2 -> result
instance TypeEq soleType soleType True where
typeEq _ _ = undefined
instance (TypeCast False result) => TypeEq type1 type2 result where
typeEq _ _ = undefined
class TypeCast type1 type2 | type1 -> type2, type2 -> type1
instance TypeCast soleType soleType
......@@ -252,6 +252,11 @@ test('tc236', expect_fail_if_compiler_lt('ghc', '6.9'), compile, [''])
test('tc237', normal, compile, [''])
test('tc238', normal, compile, [''])
test('FD1', normal, compile_fail, [''])
test('FD2', normal, compile_fail, [''])
test('FD3', normal, compile_fail, [''])
test('FD4', normal, compile, [''])
test('faxen', normal, compile, [''])
# Omitting temporarily
......
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