Commit 0ce6b6c1 authored by dwincort's avatar dwincort Committed by Simon Marlow
Browse files

Test cases for GHCi data, class, etc.

Test cases for GHCi data, type, newtype, class, instance,
deriving, etc declarations.
parent b4d34260
--Testing type synonyms
type Foo = String
let foo = "foo" :: Foo
:t foo
A.hs:1:16: parse error on input `where'
Not in scope: `yan'
Perhaps you meant `tan' (imported from Prelude)
<interactive>:1:1: Not in scope: `α'
<interactive>:2:1: Not in scope: `α'
Multiple declarations of `f'
Declared at: <interactive>:1:32
<interactive>:1:108: `f' is not a (visible) method of class `Foo'
Multiple declarations of `f'
Declared at: <interactive>:3:32
<interactive>:3:108: `f' is not a (visible) method of class `Foo'
Couldn't match type `a' with `[Char]'
In the expression: "hi"
In the expression: [x, "hi"]
......@@ -55,6 +55,23 @@ test('ghci035', normal, ghci_script, ['ghci035.script'])
test('ghci036', normal, ghci_script, ['ghci036.script'])
test('ghci037', req_interp, run_command, ['$MAKE -s --no-print-directory ghci037'])
test('ghci038', normal, ghci_script, ['ghci038.script'])
test('ghci039', normal, ghci_script, ['ghci039.script'])
test('ghci040', normal, ghci_script, ['ghci040.script'])
test('ghci041', normal, ghci_script, ['ghci041.script'])
test('ghci042', normal, ghci_script, ['ghci042.script'])
test('ghci043', normal, ghci_script, ['ghci043.script'])
test('ghci044', normal, ghci_script, ['ghci044.script'])
test('ghci045', normal, ghci_script, ['ghci045.script'])
test('ghci046', normal, ghci_script, ['ghci046.script'])
test('ghci047', normal, ghci_script, ['ghci047.script'])
test('ghci048', normal, ghci_script, ['ghci048.script'])
test('ghci049', normal, ghci_script, ['ghci049.script'])
test('ghci050', normal, ghci_script, ['ghci050.script'])
test('ghci051', normal, ghci_script, ['ghci051.script'])
test('ghci052', normal, ghci_script, ['ghci052.script'])
test('ghci053', normal, ghci_script, ['ghci053.script'])
test('ghci054', normal, ghci_script, ['ghci054.script'])
test('ghci055', normal, ghci_script, ['ghci055.script'])
test('2452', normal, ghci_script, ['2452.script'])
test('T2766', normal, ghci_script, ['T2766.script'])
($$$) :: [b -> c] -> [b] -> [c] -- Defined at <interactive>:1:8
($$$) :: [b -> c] -> [b] -> [c] -- Defined at <interactive>:2:8
--Basic deriving test
data T = A | B deriving Show
show A
--Testing type and constructor shadowing
data T = A | B
data T = B | C
:i A
data main::Interactive.T = A | ...
-- Defined at <interactive>:3:10
--Testing more shadowing
data T = A | B
data R = A | C
:i A
data R = A | ... -- Defined at <interactive>:4:10
--Testing record fields
data T = A {a :: Int}
:i A
:i a
let a = 3
:i a
data R = B {a :: Int}
:i a
:i T
data T = A {...} -- Defined at <interactive>:3:10
data T = A {a :: Int} -- Defined at <interactive>:3:13
a :: Integer -- Defined at <interactive>:6:5
data R = B {a :: Int} -- Defined at <interactive>:9:13
data T = A {main::Interactive.a :: Int}
-- Defined at <interactive>:3:6
--Testing custom classes and instances as well as data type shadowing
class C a
instance C Int
data Foo = Bar | Baz
class MyEq a where ; myeq :: a -> a -> Bool ; a `myeq` b = True
instance MyEq Foo
Bar `myeq` Baz
data Foo = Bar | Baz
instance MyEq Foo where ; a `myeq` b = False
Baz `myeq` Bar
--Testing flexible and Overlapping instances
class C a where { f :: a -> Int; f _ = 3 }
instance C Int where { f = id }
instance C [Int]
:set -XFlexibleInstances
instance C [Int]
instance C a => C [a] where f xs = length xs
-- ***This should be an overlapping instances error!***
:set -XOverlappingInstances
instance C a => C [a] where f xs = length xs
Illegal instance declaration for `C [Int]'
(All instance types must be of the form (T a1 ... an)
where a1 ... an are *distinct type variables*,
and each type variable appears at most once in the instance head.
Use -XFlexibleInstances if you want to disable this.)
In the instance declaration for `C [Int]'
Overlapping instance declarations:
instance C a => C [a] -- Defined at <interactive>:8:10
instance C [Int] -- Defined at <interactive>:7:10
--Testing standalone deriving
:set -XStandaloneDeriving
data Foo = A | B | C
deriving instance Show Foo
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