summaryrefslogtreecommitdiff
path: root/testsuite/tests/typecheck/should_run/tcrun040.hs
blob: adfaf95898cf23249c9a3d5af503bde7ed147fea (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
-- Sven Panne found this example; a mistake in typechecking 
-- lazy patterns made functions too strict in a version of
-- GHC 6.7

module Main where

import Foreign

-- Strangely enough, this works if newtype is used...
data Elem a = Elem a

instance Storable a => Storable (Elem a) where
   sizeOf ~(Elem r) = 3 * sizeOf r
   alignment ~(Elem r) = alignment r
   peek ptr = do r <- peekElemOff (castPtr ptr) 0; return (Elem r)
   poke ptr (Elem r) = poke (castPtr ptr) r

main :: IO ()
main = do
   putStrLn "*** main 1"
   allocaBytes 100 $ \buf -> do
      poke buf (Elem 12345)
      putStrLn "*** main 2"
      Elem x <- peekElemOff buf 0
      print (x :: Int)
      putStrLn "*** main 3"