4 newtype Ptr a = Ptr Addr
10 foreign export dynamic
11 mkComparator :: (Ptr Int -> Ptr Int -> IO CInt)
12 -> IO (Ptr (Ptr Int -> Ptr Int -> IO CInt))
15 qsort :: Addr -> CSize -> CSize -> Ptr (Ptr Int -> Ptr Int -> IO CInt)
18 compareInts :: Ptr Int -> Ptr Int -> IO CInt
19 compareInts a1 a2 = do
22 return (fromIntegral (i1 - i2 :: Int))
26 let values = [ 12, 56, 90, 34, 78 ] :: [Int]
28 buf <- mallocElems (head values) n
29 zipWithM_ (pokeElemOff buf) [ 0 .. ] values
30 c <- mkComparator compareInts
31 qsort buf (fromIntegral n) (fromIntegral (sizeOf (head values))) c
32 mapM (peekElemOff buf) [ 0 .. n-1 ] >>= (print :: [Int] -> IO ())