summaryrefslogtreecommitdiff
path: root/testsuite/tests/typecheck/should_fail/T13506.hs
blob: 84e8fa95925f488e10fc9b38a459a1d2d25d0f15 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
{-# LANGUAGE FlexibleInstances, FunctionalDependencies, MultiParamTypeClasses #-}
module Bug where

class FunDep lista a | lista -> a
instance FunDep [a] a

singleton :: FunDep lista a => a -> lista
singleton _ = undefined

-- this error is expected:
--   Couldn't match type 'Char' with '()'
--   arising from a functional dependency between
--     constraint 'FunDep [Char] ()' arising from a use of 'singleton'
--     instance 'FunDep [a] a'
illTyped :: [Char]
illTyped = singleton ()
  {-  [W] FunDep [Char] () -}

-- but this one is not:
--   Couldn't match type '()' with 'Char'
--     arising from a functional dependency between constraints:
--       'FunDep [Char] Char' arising from a use of 'singleton' (in 'wellTyped')
--       'FunDep [Char] ()' arising from a use of 'singleton' (in 'illTyped')
wellTyped :: [Char]
wellTyped = singleton 'a'
  {-   [W] FunDep [Char] Char -}