ffi-deriv1.hs 694 Bytes
Newer Older
thoughtpolice's avatar
thoughtpolice committed
1
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
2 3 4 5 6 7 8

-- 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

thoughtpolice's avatar
thoughtpolice committed
9 10
import Control.Applicative (Applicative)

11
import Foreign.Ptr
thoughtpolice's avatar
thoughtpolice committed
12
newtype RenderM a = RenderM (IO a) deriving (Functor, Applicative, Monad)
13 14 15 16 17 18 19 20 21 22 23 24 25

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