blob: d9dbd25b9cfdb87bfb0e2b8036fa9315eea747ee (
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
28
29
30
31
32
33
|
{-# LANGUAGE MagicHash, UnboxedTuples , ScopedTypeVariables #-}
module Main where
import GHC.Prim
import GHC.Types
import Foreign
import Foreign.Ptr
import GHC.Ptr
wrapFetch :: (a -> State# RealWorld -> State# RealWorld) -> (a -> IO ())
wrapFetch prefetch a = IO (\ s -> (# prefetch a s, ()#))
main :: IO ()
main = do
(ptr :: Ptr Int) <- malloc
wrapFetch (\ (Ptr adr)-> prefetchAddr3# adr 0# ) ptr
wrapFetch prefetchValue1# (1 ::Int)
wrapFetch prefetchValue2# "hiiii"
wrapFetch prefetchValue3# (Just "testing")
wrapFetch prefetchValue0# (error "this shouldn't get evaluated")
-- -- ^^ this is to make sure it doesn't force thunks!
--incontrast,
--wrapFetch prefetchValue0# $! (error "this shouldn't get evaluated")
-- would trigger an exception
putStrLn "success"
|