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