4 newtype XPtr a = XPtr Addr
10 foreign export dynamic
11 mkComparator :: (XPtr Int -> XPtr Int -> IO CInt)
12 -> IO (XPtr (XPtr Int -> XPtr Int -> IO CInt))
15 qsort :: Ptr Int -> CSize -> CSize -> XPtr (XPtr Int -> XPtr Int -> IO CInt)
18 compareInts :: XPtr Int -> XPtr Int -> IO CInt
19 compareInts a1 a2 = do
20 i1 <- peek (Ptr (unXPtr a1))
21 i2 <- peek (Ptr (unXPtr a2))
22 return (fromIntegral (i1 - i2 :: Int))
26 let values = [ 12, 56, 90, 34, 78 ] :: [Int]
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 ())