Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
GHC
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Locked Files
Issues
4,323
Issues
4,323
List
Boards
Labels
Service Desk
Milestones
Iterations
Merge Requests
373
Merge Requests
373
Requirements
Requirements
List
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Security & Compliance
Security & Compliance
Dependency List
License Compliance
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Code Review
Insights
Issue
Repository
Value Stream
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Glasgow Haskell Compiler
GHC
Commits
69cc9a59
Commit
69cc9a59
authored
May 02, 2011
by
dreixel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add some tests for the new generic deriving mechanism.
parent
a07c8a4f
Changes
16
Hide whitespace changes
Inline
Side-by-side
Showing
16 changed files
with
221 additions
and
0 deletions
+221
-0
testsuite/tests/ghc-regress/generics/GEq/GEq.hs
testsuite/tests/ghc-regress/generics/GEq/GEq.hs
+47
-0
testsuite/tests/ghc-regress/generics/GEq/GEq1.stdout
testsuite/tests/ghc-regress/generics/GEq/GEq1.stdout
+3
-0
testsuite/tests/ghc-regress/generics/GEq/Main.hs
testsuite/tests/ghc-regress/generics/GEq/Main.hs
+31
-0
testsuite/tests/ghc-regress/generics/GEq/Makefile
testsuite/tests/ghc-regress/generics/GEq/Makefile
+3
-0
testsuite/tests/ghc-regress/generics/GEq/test.T
testsuite/tests/ghc-regress/generics/GEq/test.T
+3
-0
testsuite/tests/ghc-regress/generics/Makefile
testsuite/tests/ghc-regress/generics/Makefile
+3
-0
testsuite/tests/ghc-regress/generics/Uniplate/Main.hs
testsuite/tests/ghc-regress/generics/Uniplate/Main.hs
+20
-0
testsuite/tests/ghc-regress/generics/Uniplate/Makefile
testsuite/tests/ghc-regress/generics/Uniplate/Makefile
+3
-0
testsuite/tests/ghc-regress/generics/Uniplate/Uniplate.hs
testsuite/tests/ghc-regress/generics/Uniplate/Uniplate.hs
+53
-0
testsuite/tests/ghc-regress/generics/Uniplate/Uniplate1.stdout
...uite/tests/ghc-regress/generics/Uniplate/Uniplate1.stdout
+1
-0
testsuite/tests/ghc-regress/generics/Uniplate/test.T
testsuite/tests/ghc-regress/generics/Uniplate/test.T
+3
-0
testsuite/tests/ghc-regress/generics/all.T
testsuite/tests/ghc-regress/generics/all.T
+7
-0
testsuite/tests/ghc-regress/generics/canDoRep0.hs
testsuite/tests/ghc-regress/generics/canDoRep0.hs
+14
-0
testsuite/tests/ghc-regress/generics/cannotDoRep0.hs
testsuite/tests/ghc-regress/generics/cannotDoRep0.hs
+9
-0
testsuite/tests/ghc-regress/generics/cannotDoRep1.hs
testsuite/tests/ghc-regress/generics/cannotDoRep1.hs
+8
-0
testsuite/tests/ghc-regress/generics/cannotDoRep2.hs
testsuite/tests/ghc-regress/generics/cannotDoRep2.hs
+13
-0
No files found.
testsuite/tests/ghc-regress/generics/GEq/GEq.hs
0 → 100644
View file @
69cc9a59
{-# LANGUAGE TypeOperators, Generics, FlexibleContexts, FlexibleInstances #-}
module
GEq
where
import
GHC.Generics
class
GEq'
f
where
geq'
::
f
a
->
f
a
->
Bool
instance
GEq'
U1
where
geq'
_
_
=
True
instance
GEq'
(
K1
P
c
)
where
geq'
(
K1
a
)
(
K1
b
)
=
undefined
instance
(
GEq
c
)
=>
GEq'
(
K1
R
c
)
where
geq'
(
K1
a
)
(
K1
b
)
=
geq
a
b
-- No instances for P or Rec because geq is only applicable to types of kind *
instance
(
GEq'
a
)
=>
GEq'
(
M1
i
c
a
)
where
geq'
(
M1
a
)
(
M1
b
)
=
geq'
a
b
instance
(
GEq'
a
,
GEq'
b
)
=>
GEq'
(
a
:+:
b
)
where
geq'
(
L1
a
)
(
L1
b
)
=
geq'
a
b
geq'
(
R1
a
)
(
R1
b
)
=
geq'
a
b
geq'
_
_
=
False
instance
(
GEq'
a
,
GEq'
b
)
=>
GEq'
(
a
:*:
b
)
where
geq'
(
a1
:*:
b1
)
(
a2
:*:
b2
)
=
geq'
a1
a2
&&
geq'
b1
b2
class
GEq
a
where
geq
::
a
->
a
->
Bool
default
geq
::
(
Representable0
a
,
GEq'
(
Rep0
a
))
=>
a
->
a
->
Bool
geq
x
y
=
geq'
(
from0
x
)
(
from0
y
)
-- Base types instances (ad-hoc)
instance
GEq
Char
where
geq
=
(
==
)
instance
GEq
Int
where
geq
=
(
==
)
instance
GEq
Float
where
geq
=
(
==
)
{-
-- Generic instances
instance (GEq a) => GEq (Maybe a)
instance (GEq a) => GEq [a]
-}
testsuite/tests/ghc-regress/generics/GEq/GEq1.stdout
0 → 100644
View file @
69cc9a59
False
False
True
testsuite/tests/ghc-regress/generics/GEq/Main.hs
0 → 100644
View file @
69cc9a59
{-# LANGUAGE TypeOperators, Generics #-}
module
Main
where
import
GHC.Generics
hiding
(
C
,
D
)
import
GEq
-- We should be able to generate a generic representation for these types
data
C
=
C0
|
C1
data
D
a
=
D0
|
D1
{
d11
::
a
,
d12
::
(
D
a
)
}
-- Example values
c0
=
C0
c1
=
C1
d0
::
D
Char
d0
=
D0
d1
=
D1
'p'
D0
-- Generic instances
instance
GEq
C
instance
(
GEq
a
)
=>
GEq
(
D
a
)
-- Tests
teq0
=
geq
c0
c1
teq1
=
geq
d0
d1
teq2
=
geq
d0
d0
main
=
mapM_
print
[
teq0
,
teq1
,
teq2
]
testsuite/tests/ghc-regress/generics/GEq/Makefile
0 → 100644
View file @
69cc9a59
TOP
=
../../../..
include
$(TOP)/mk/boilerplate.mk
include
$(TOP)/mk/test.mk
testsuite/tests/ghc-regress/generics/GEq/test.T
0 → 100644
View file @
69cc9a59
setTestOpts
(
only_compiler_types
(['
ghc
']))
test
('
GEq1
',
normal
,
multimod_compile_and_run
,
['
Main
',
''])
\ No newline at end of file
testsuite/tests/ghc-regress/generics/Makefile
0 → 100644
View file @
69cc9a59
TOP
=
../../..
include
$(TOP)/mk/boilerplate.mk
include
$(TOP)/mk/test.mk
testsuite/tests/ghc-regress/generics/Uniplate/Main.hs
0 → 100644
View file @
69cc9a59
{-# LANGUAGE Generics #-}
module
Main
where
import
GHC.Generics
import
Uniplate
data
Tree
=
Leaf
|
Node
Int
Tree
Tree
deriving
Show
data
Pair
a
b
=
Pair
a
b
deriving
Show
instance
Uniplate
Tree
instance
Uniplate
(
Pair
a
b
)
-- Tests
t1
=
children
(
'p'
)
t2
=
children
(
Pair
"abc"
(
Pair
"abc"
2
))
t3
=
children
(
Node
2
Leaf
Leaf
)
main
=
print
(
t1
,
t2
,
t3
)
testsuite/tests/ghc-regress/generics/Uniplate/Makefile
0 → 100644
View file @
69cc9a59
TOP
=
../../../..
include
$(TOP)/mk/boilerplate.mk
include
$(TOP)/mk/test.mk
testsuite/tests/ghc-regress/generics/Uniplate/Uniplate.hs
0 → 100644
View file @
69cc9a59
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeSynonymInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE Generics #-}
{-# LANGUAGE IncoherentInstances #-}
-- necessary, unfortunately
module
Uniplate
where
import
GHC.Generics
--------------------------------------------------------------------------------
-- Generic Uniplate
--------------------------------------------------------------------------------
class
Uniplate'
f
b
where
children'
::
f
a
->
[
b
]
instance
Uniplate'
U1
a
where
children'
U1
=
[]
instance
Uniplate'
(
K1
i
a
)
a
where
children'
(
K1
a
)
=
[
a
]
instance
Uniplate'
(
K1
i
a
)
b
where
children'
(
K1
_
)
=
[]
instance
(
Uniplate'
f
b
)
=>
Uniplate'
(
M1
i
c
f
)
b
where
children'
(
M1
a
)
=
children'
a
instance
(
Uniplate'
f
b
,
Uniplate'
g
b
)
=>
Uniplate'
(
f
:+:
g
)
b
where
children'
(
L1
a
)
=
children'
a
children'
(
R1
a
)
=
children'
a
instance
(
Uniplate'
f
b
,
Uniplate'
g
b
)
=>
Uniplate'
(
f
:*:
g
)
b
where
children'
(
a
:*:
b
)
=
children'
a
++
children'
b
class
Uniplate
a
where
children
::
a
->
[
a
]
default
children
::
(
Representable0
a
,
Uniplate'
(
Rep0
a
)
a
)
=>
a
->
[
a
]
children
=
children'
.
from0
-- Base types instances
instance
Uniplate
Char
where
children
_
=
[]
instance
Uniplate
Int
where
children
_
=
[]
instance
Uniplate
Float
where
children
_
=
[]
instance
Uniplate
[
a
]
where
children
[]
=
[]
children
(
_
:
t
)
=
[
t
]
testsuite/tests/ghc-regress/generics/Uniplate/Uniplate1.stdout
0 → 100644
View file @
69cc9a59
("",[],[Leaf,Leaf])
testsuite/tests/ghc-regress/generics/Uniplate/test.T
0 → 100644
View file @
69cc9a59
setTestOpts
(
only_compiler_types
(['
ghc
']))
test
('
Uniplate1
',
normal
,
multimod_compile_and_run
,
['
Main
',
''])
\ No newline at end of file
testsuite/tests/ghc-regress/generics/all.T
0 → 100644
View file @
69cc9a59
setTestOpts
(
only_compiler_types
(['
ghc
']))
test
('
canDoRep0
',
normal
,
compile
,
[''])
test
('
cannotDoRep0
',
normal
,
compile_fail
,
[''])
test
('
cannotDoRep1
',
normal
,
compile_fail
,
[''])
test
('
cannotDoRep2
',
normal
,
compile_fail
,
[''])
testsuite/tests/ghc-regress/generics/canDoRep0.hs
0 → 100644
View file @
69cc9a59
{-# LANGUAGE Generics #-}
module
ShouldCompile0
where
-- We should be able to generate a generic representation for these types
data
A
data
B
a
data
C
=
C0
|
C1
data
D
a
=
D0
|
D1
{
d11
::
a
,
d12
::
(
D
a
)
}
data
E
a
=
E0
a
(
E
a
)
(
D
a
)
testsuite/tests/ghc-regress/generics/cannotDoRep0.hs
0 → 100644
View file @
69cc9a59
{-# LANGUAGE DeriveRepresentable #-}
{-# LANGUAGE ExistentialQuantification #-}
module
ShouldFail0
where
import
GHC.Generics
-- We do not support existential quantification
data
Dynamic
=
forall
a
.
Dynamic
a
deriving
Representable0
testsuite/tests/ghc-regress/generics/cannotDoRep1.hs
0 → 100644
View file @
69cc9a59
{-# LANGUAGE DeriveRepresentable #-}
module
ShouldFail1
where
import
GHC.Generics
-- We do not support datatypes with context
data
(
Show
a
)
=>
Context
a
=
Context
a
deriving
Representable0
testsuite/tests/ghc-regress/generics/cannotDoRep2.hs
0 → 100644
View file @
69cc9a59
{-# LANGUAGE DeriveRepresentable #-}
{-# LANGUAGE StandaloneDeriving #-}
{-# LANGUAGE GADTs #-}
module
ShouldFail2
where
import
GHC.Generics
-- We do not support GADTs
data
Term
a
where
Int
::
Term
Int
deriving
instance
Representable0
(
Term
a
)
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment