[project @ 2000-09-05 12:35:09 by simonmar]
authorsimonmar <unknown>
Tue, 5 Sep 2000 12:35:09 +0000 (12:35 +0000)
committersimonmar <unknown>
Tue, 5 Sep 2000 12:35:09 +0000 (12:35 +0000)
Use newtype Ptr instead of just Addr, test newtypes in foreign decls.

ghc/tests/ccall/should_run/fed001.hs

index 22a4352..be0852c 100644 (file)
@@ -1,16 +1,24 @@
 import Foreign
 import Monad
 
+newtype Ptr a = Ptr Addr
+unPtr (Ptr x) = x
+
 type CInt  = Int32
 type CSize = Word32
 
-foreign export dynamic mkComparator :: (Addr -> Addr -> IO CInt) -> IO Addr
-foreign import qsort :: Addr -> CSize -> CSize -> Addr -> IO ()
+foreign export dynamic 
+   mkComparator :: (Ptr Int -> Ptr Int -> IO CInt) 
+               -> IO (Ptr (Ptr Int -> Ptr Int -> IO CInt))
+
+foreign import 
+   qsort :: Addr -> CSize -> CSize -> Ptr (Ptr Int -> Ptr Int -> IO CInt) 
+        -> IO ()
 
-compareInts :: Addr -> Addr -> IO CInt
+compareInts :: Ptr Int -> Ptr Int -> IO CInt
 compareInts a1 a2 = do
-   i1 <- peek a1
-   i2 <- peek a2
+   i1 <- peek (unPtr a1)
+   i2 <- peek (unPtr a2)
    return (fromIntegral (i1 - i2 :: Int))
 
 main :: IO ()