Commit eaf6a58a authored by batterseapower's avatar batterseapower
Browse files

Test associated type defaults

parent 12850c11
SimpleFail4.hs:8:11:
Unexpected type `Int' where type variable expected
In the declaration of `S2 Int'
SimpleFail4.hs:8:3:
Type indexes must match class instance head
Found `Int' but expected `a'
In the type synonym instance declaration for `S2'
In the class declaration for `C2'
{-# LANGUAGE TypeFamilies #-}
module Tc251_Help where
class Cls a where
type Fam a :: *
type Fam a = Maybe a
......@@ -340,6 +340,12 @@ test('T4969', normal, compile, [''])
test('T5120', normal, compile, [''])
test('mc18', normal, compile, [''])
test('tc249', normal, compile, [''])
test('tc250', normal, compile, [''])
test('tc251', extra_clean(['Tc251_Help.hi', 'Tc251_Help.o']),
multisrc_compile, ['tc251', ['Tc251_Help.hs'], '-v0'])
test('tc252', normal, compile, [''])
test('tc253', normal, compile, [''])
test('tc254', normal, compile, [''])
test('GivenOverlapping', normal, compile, [''])
test('SilentParametersOverlapping', normal, compile, [''])
......
{-# LANGUAGE TypeFamilies #-}
module ShouldCompile where
class Cls a where
type Fam a :: *
type Fam a = Maybe a
instance Cls Int where
-- Gets type family from default
inc :: (Fam a ~ Maybe Int) => a -> Fam a -> Fam a
inc _proxy (Just x) = Just (x + 1)
inc _proxy Nothing = Just 0
foo :: Maybe Int -> Maybe Int
foo = inc (undefined :: Int)
{-# LANGUAGE TypeFamilies #-}
module ShouldCompile where
import Tc251_Help
instance Cls Int where
inc :: (Fam a ~ Maybe Int) => a -> Fam a -> Fam a
inc _proxy (Just x) = Just (x + 1)
inc _proxy Nothing = Just 0
foo :: Maybe Int -> Maybe Int
foo = inc (undefined :: Int)
{-# LANGUAGE TypeFamilies #-}
module ShouldCompile where
class Cls a where
type Fam a :: *
type Fam a = Maybe a
instance Cls Int where
-- Overriding default
type Fam Int = Bool
nott :: (Fam a ~ Bool) => a -> Fam a -> Fam a
nott _proxy False = True
nott _proxy True = False
foo :: Bool -> Bool
foo = nott (undefined :: Int)
{-# LANGUAGE TypeFamilies #-}
module ShouldCompile where
class Cls a where
type Fam a b :: *
-- Multiple defaults!
type Fam a Bool = Maybe a
type Fam a Int = (String, a)
instance Cls Int where
-- Gets type family from default
inc :: (Fam a Bool ~ Maybe Int, Fam a Int ~ (String, Int)) => a -> Fam a Bool -> Fam a Int -> Fam a Bool
inc _proxy (Just x) (_, y) = Just (x + y + 1)
inc _proxy Nothing (_, y) = Just y
foo :: Maybe Int -> (String, Int) -> Maybe Int
foo = inc (undefined :: Int)
{-# LANGUAGE TypeFamilies #-}
{-# OPTIONS_GHC -fwarn-missing-methods #-}
module AssocTyDef01 where
class Cls a where
type Typ a
instance Cls Int where
-- No default: should get warning
\ No newline at end of file
tc254.hs:8:1:
Warning: No explicit AT declaration for `Typ'
In the instance declaration for `Cls Int'
{-# LANGUAGE TypeFamilies #-}
module AssocTyDef01 where
class OtherCls a where
type OtherTyp a
class Cls a where
type Typ a
type OtherType a = Int
-- Default for another class AT: want error
AssocTyDef01.hs:9:10:
`OtherType' is not a (visible) associated type of class `Cls'
{-# LANGUAGE TypeFamilies #-}
module AssocTyDef02 where
class Cls a where
type Typ a
type Typ b = Int
-- Default is not parametric in type class params
AssocTyDef02.hs:6:5:
Type indexes must match class instance head
Found `b' but expected `a'
In the type synonym instance declaration for `Typ'
In the class declaration for `Cls'
{-# LANGUAGE TypeFamilies #-}
module AssocTyDef03 where
class Cls a where
data Typ a
type Typ a = Int
-- Default for data family :-(
\ No newline at end of file
AssocTyDef03.hs:6:5:
Wrong category of family instance; declaration was for a data type
In the type synonym instance declaration for `Typ'
In the class declaration for `Cls'
{-# LANGUAGE TypeFamilies #-}
module AssocTyDef04 where
class Cls a where
type Typ a
type Typ a = Maybe
-- Wrong kind for default
\ No newline at end of file
AssocTyDef04.hs:6:18:
`Maybe' is not applied to enough type arguments
Expected kind `*', but `Maybe' has kind `* -> *'
In the type `Maybe'
In the type synonym instance declaration for `Typ'
In the class declaration for `Cls'
{-# LANGUAGE TypeFamilies #-}
module AssocTyDef05 where
class Cls a where
type Typ a
type Typ = Maybe
-- Too few params for default
\ No newline at end of file
AssocTyDef05.hs:6:5:
Number of parameters must match family declaration; expected 1
In the type synonym instance declaration for `Typ'
In the class declaration for `Cls'
{-# LANGUAGE TypeFamilies #-}
module AssocTyDef06 where
class Cls a where
type Typ a
type Typ a Int = Int
-- Too many params for default
\ No newline at end of file
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