7 foreign export dynamic mkComparator :: (Addr -> Addr -> IO CInt) -> IO Addr
8 foreign import qsort :: Addr -> CSize -> CSize -> Addr -> IO ()
10 compareInts :: Addr -> Addr -> IO CInt
11 compareInts a1 a2 = do
14 return (fromIntegral (i1 - i2 :: Int))
18 let values = [ 12, 56, 90, 34, 78 ] :: [Int]
20 buf <- mallocElems (head values) n
21 zipWithM_ (pokeElemOff buf) [ 0 .. ] values
22 c <- mkComparator compareInts
23 qsort buf (fromIntegral n) (fromIntegral (sizeOf (head values))) c
24 mapM (peekElemOff buf) [ 0 .. n-1 ] >>= (print :: [Int] -> IO ())