Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in / Register
Toggle navigation
Menu
Open sidebar
Alex D
GHC
Commits
91252ef0
Commit
91252ef0
authored
Jan 07, 2014
by
Simon Peyton Jones
Browse files
Test Trac #5498
parent
b014797d
Changes
3
Hide whitespace changes
Inline
Side-by-side
testsuite/tests/deriving/should_fail/T5498.hs
0 → 100644
View file @
91252ef0
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
-- | We use newtype to create an isomorphic type to Int
-- with a reversed Ord dictionary. We now use the MinList
-- API of MinList to create a new MinList. Then we use newtype
-- deriving to convert the newtype MinList to an Int
-- MinList. This final result breaks the invariants of
-- MinList which shouldn't be possible with the exposed
-- API of MinList.
module
T5498
where
data
MinList
a
=
MinList
a
[
a
]
newMinList
::
Ord
a
=>
a
->
MinList
a
newMinList
n
=
MinList
n
[]
insertMinList
::
Ord
a
=>
MinList
a
->
a
->
MinList
a
insertMinList
s
@
(
MinList
m
xs
)
n
|
n
>
m
=
MinList
m
(
n
:
xs
)
|
otherwise
=
s
printIntMinList
::
MinList
Int
->
IO
()
printIntMinList
(
MinList
min
xs
)
=
putStrLn
$
"MinList Int :: MinList "
++
show
min
++
" "
++
show
xs
class
IntIso
t
where
intIso
::
c
t
->
c
Int
instance
IntIso
Int
where
intIso
=
id
newtype
Down
a
=
Down
a
deriving
(
Eq
,
IntIso
)
instance
Ord
a
=>
Ord
(
Down
a
)
where
compare
(
Down
a
)
(
Down
b
)
=
compare
b
a
fine
::
MinList
(
Down
Int
)
fine
=
foldl
(
\
x
y
->
insertMinList
x
$
Down
y
)
(
newMinList
$
Down
0
)
[
-
1
,
-
2
,
-
3
,
-
4
,
1
,
2
,
3
,
4
]
bad
::
MinList
Int
bad
=
intIso
fine
testsuite/tests/deriving/should_fail/T5498.stderr
0 → 100644
View file @
91252ef0
\ No newline at end of file
testsuite/tests/deriving/should_fail/all.T
View file @
91252ef0
...
...
@@ -47,3 +47,4 @@ test('T4846', normal, compile_fail, [''])
test
('
T7148
',
normal
,
compile_fail
,
[''])
test
('
T7148a
',
normal
,
compile_fail
,
[''])
test
('
T7800
',
normal
,
multimod_compile_fail
,
['
T7800
',''])
test
('
T5498
',
normal
,
compile_fail
,
[''])
Write
Preview
Supports
Markdown
0%
Try again
or
attach a new 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