[project @ 1999-06-09 09:35:54 by simonpj]
[ghc-hetmet.git] / ghc / tests / lib / should_run / stableptr001.hs
1 {-# OPTIONS -fglasgow-exts #-}
2
3 module Main where
4
5 import Foreign
6 import Stable
7
8 -- simple test for building/dereferencing stable ptrs
9
10 main 
11   = do  l <- mapM makeStablePtr [1..100000]
12         sum <- stable_sum l
13         print sum
14
15 stable_sum :: [StablePtr Integer] -> IO Integer
16 stable_sum [] = return 0
17 stable_sum (x:xs) 
18   = do  x'  <- deRefStablePtr x
19         freeStablePtr x
20         xs' <- stable_sum xs
21         return (x' + xs')