Testsuite: tabs -> spaces [skip ci]
[ghc.git] / testsuite / tests / typecheck / should_compile / tc091.hs
1 {-# OPTIONS_GHC -fno-warn-redundant-constraints #-}
2
3 -- !!! Test polymorphic recursion
4
5
6 -- With polymorphic recursion this one becomes legal
7 -- SLPJ June 97.
8
9 {-
10 To: Lennart Augustsson <augustss@cs.chalmers.se>
11 Cc: partain@dcs.gla.ac.uk, John Peterson (Yale) <peterson-john@cs.yale.edu>,
12 simonpj@dcs.gla.ac.uk
13 Subject: Type checking matter
14 Date: Fri, 23 Oct 92 15:28:38 +0100
15 From: Simon L Peyton Jones <simonpj@dcs.gla.ac.uk>
16
17
18 I've looked at the enclosed again. It seems to me that
19 since "s" includes a recursive call to "sort", inside the body
20 of "sort", then "sort" is monomorphic, and hence so is "s";
21 hence the type signature (which claims full polymorphism) is
22 wrong.
23
24 [Lennart says he can't see any free variables inside "s", but there
25 is one, namely "sort"!]
26
27 Will: one for the should-fail suite?
28
29 Simon
30
31
32 ------- Forwarded Message
33
34
35 From: Lennart Augustsson <augustss@cs.chalmers.se>
36 To: partain
37 Subject: Re: just to show you I'm a nice guy...
38 Date: Tue, 26 May 92 17:30:12 +0200
39
40 > Here's a fairly simple module from our compiler, which includes what
41 > we claim is an illegal type signature (grep ILLEGAL ...).
42 > Last time I checked, hbc accepted this module.
43
44 Not that I don't believe you, but why is this illegal?
45 As far as I can see there are no free variables in the function s,
46 which makes me believe that it can typechecked like a top level
47 definition. And for a top level defn the signature should be
48 all right.
49
50 -- Lennart
51 - ------- End of forwarded message -------
52 -}
53 module ShouldSucceed where
54
55 sort :: Ord a => [a] -> [a]
56 sort xs = s xs (length xs)
57 where
58 s :: Ord b => [b] -> Int -> [b] -- This signature is WRONG
59 s xs k = if k <= 1 then xs
60 else merge (sort ys) (sort zs)
61 where (ys,zs) = init_last xs (k `div` (2::Int))
62
63 -- Defns of merge and init_last are just dummies with the correct types
64 merge :: Ord a => [a] -> [a] -> [a]
65 merge xs ys = xs
66
67 init_last :: [a] -> Int -> ([a],[a])
68 init_last a b = (a,a)
69