Skip to content
Snippets Groups Projects
Commit ceb975cd authored by sof's avatar sof
Browse files

[project @ 1999-11-02 11:55:02 by sof]

Simple example of callback'ery in action
parent 3b8b96b3
No related branches found
No related tags found
No related merge requests found
-- !!! Testing callbacks
module Main(main) where
import IOExts
import Addr
count :: IORef Int -> IO Int
count ref = do
x <- readIORef ref
writeIORef ref (x+1)
return x
createCounter :: IO Addr
createCounter = do
ref <- newIORef 0
mkCounter (count ref)
foreign export dynamic mkCounter :: (IO Int) -> IO Addr
main :: IO ()
main = do
x <- createCounter
v1 <- _casm_GC_ `` do { typedef int (*f)(); %r=(int)((f)%0)();} while (0); '' x
print (v1::Int)
v2 <- _casm_GC_ `` do { typedef int (*f)(); %r=(int)((f)%0)();} while (0); '' x
print (v2::Int)
TOP = ..
include $(TOP)/mk/boilerplate.mk
SRC_HC_OPTS += -fglasgow-exts
CC = $(HC)
all :: runtest
include $(TOP)/mk/target.mk
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment