Commit 550a5224 authored by Simon Peyton Jones's avatar Simon Peyton Jones
Browse files

Add test for newtypes in FFI

The standard FFI says that newtypes are automatically unwrapped in
argument and result types.  This test checks that it also happens
for newtype-wrapping of the IO monad itself, a recent change to
GHC.
parent 2a41e3be
......@@ -30,3 +30,4 @@ test('cc010', expect_fail_for(['extcore','optextcore']), compile, [''])
test('cc011', normal, compile, [''])
test('cc012', normal, compile, [''])
test('ffi001', normal, compile, [''])
test('ffi-deriv1', normal, compile, [''])
{-# OPTIONS -fglasgow-exts #-}
-- Tests newtype unwrapping for the IO monad itself
-- Notice the RenderM monad, which is used in the
-- type of the callback function
module ShouldCompile where
import Foreign.Ptr
newtype RenderM a = RenderM (IO a) deriving (Functor, Monad)
type RenderCallback = Int -> Int -> RenderM ()
foreign import ccall duma_onRender :: FunPtr RenderCallback -> RenderM ()
foreign import ccall "wrapper" mkRenderCallback
:: RenderCallback -> RenderM (FunPtr RenderCallback)
onRender :: RenderCallback -> RenderM ()
onRender f = mkRenderCallback f >>= duma_onRender
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment