[project @ 2000-11-28 08:25:57 by simonpj]
[ghc-hetmet.git] / ghc / tests / typecheck / should_compile / tc110.hs
1 {-# OPTIONS -fglasgow-exts #-}
2
3 module ShouldCompile where
4
5 -- A stripped down functional-dependency 
6 -- example that causes GHC 4.08.1 to crash with:
7 -- "basicTypes/Var.lhs:194: Non-exhaustive patterns in function readMutTyVar"
8 -- Reported by Thomas Hallgren Nov 00
9
10
11 foo = dup 1 >>= print
12
13 foreign import "dup" primDup :: Int -> IO Int
14 --dup :: Int -> IO Int               -- not needed with (1), needed with (2)
15 dup = call primDup                   -- ghc crashes here with (1), ok with (2)
16
17 class Call    c h | c -> h where call  :: c -> h            -- (1) problematic
18 --class Call    c h          where call  :: c -> h          -- (2) ok
19
20 class Result  c h | c -> h where fromC :: c -> IO h
21
22 instance Result c h => Call (IO c) (IO h) where call f = fromC =<< f
23 instance Call c h => Call (Int->c) (Int->h) where call f = call . f
24
25 instance Result Int Int where fromC = return
26
27
28 {-
29 The example is perhaps too stripped down to illustrate the purpose of these
30 classes, but the idea is that the class "Call" should relate suitably declared
31 low-level prim_types in foreign imports to sensible, high-level Haskell types,
32 allowing high level functions to be obtained by simply applying the method
33 "call" to the primitive function, as in the definition of dup above, without
34 having to explicitly give also the type of the high level function.
35 -}