summaryrefslogtreecommitdiff
path: root/testsuite/tests/lib/should_run/stableptr001.hs
blob: 1bc857aba6f9391e4ebf2517e8d88b0310727482 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19

module Main where

import Foreign

-- simple test for building/dereferencing stable ptrs

main 
  = do	l <- mapM newStablePtr [1..100000]
   	sum <- stable_sum l
   	print sum

stable_sum :: [StablePtr Integer] -> IO Integer
stable_sum [] = return 0
stable_sum (x:xs) 
  = do 	x'  <- deRefStablePtr x
	freeStablePtr x
       	xs' <- stable_sum xs
        return (x' + xs')