# Pastebin KfZMf1Tg main = do -- Let's read a number from input... putStrLn "Enter a nonnegative integer: " s <- getLine let n = read s :: CInt -- use this number with the C function a couple times stuff <- createStuff n doubleStuff <- createStuff (n * 2) -- then finally print the return value of the C function! traverse f stuff traverse f doubleStuff -- note that f does not deallocate its argument -- that is done automatically by the GC later -- withForeignPtr is used to "downgrade" ForeignPtr to a Ptr where f fPtr = withForeignPtr fPtr (\p -> do -- convert a C char* to a -- Haskell String xs <- peekCString p putStrLn xs)