Update examples
This commit is contained in:
4
testsuite/dynload/poly/Makefile
Normal file
4
testsuite/dynload/poly/Makefile
Normal file
@ -0,0 +1,4 @@
|
||||
TEST=dynload/poly
|
||||
EXTRA_OBJS=Plugin.o
|
||||
TOP=../../..
|
||||
include ../../build.mk
|
12
testsuite/dynload/poly/Plugin.hs
Normal file
12
testsuite/dynload/poly/Plugin.hs
Normal file
@ -0,0 +1,12 @@
|
||||
module Plugin where
|
||||
|
||||
import API
|
||||
import AltData.Dynamic
|
||||
|
||||
my_fun = plugin {
|
||||
equals = \x y -> (x /= y) -- a strange equals function :)
|
||||
}
|
||||
|
||||
resource_dyn :: Dynamic
|
||||
resource_dyn = toDyn my_fun
|
||||
|
24
testsuite/dynload/poly/api/API.hs
Normal file
24
testsuite/dynload/poly/api/API.hs
Normal file
@ -0,0 +1,24 @@
|
||||
{-# OPTIONS -cpp #-}
|
||||
|
||||
module API where
|
||||
|
||||
import AltData.Typeable
|
||||
|
||||
data Interface = Interface {
|
||||
equals :: forall t. Eq t => t -> t -> Bool
|
||||
}
|
||||
|
||||
--
|
||||
-- see how it hides the internal type.. but to compile GHC still checks
|
||||
-- the type.
|
||||
--
|
||||
instance Typeable Interface where
|
||||
#if __GLASGOW_HASKELL__ >= 603
|
||||
typeOf i = mkTyConApp (mkTyCon "API.Interface") []
|
||||
#else
|
||||
typeOf i = mkAppTy (mkTyCon "API.Interface") []
|
||||
#endif
|
||||
|
||||
plugin :: Interface
|
||||
plugin = Interface { equals = (==) }
|
||||
|
17
testsuite/dynload/poly/prog/Main.hs
Normal file
17
testsuite/dynload/poly/prog/Main.hs
Normal file
@ -0,0 +1,17 @@
|
||||
{-# OPTIONS -cpp #-}
|
||||
|
||||
#include "../../../../config.h"
|
||||
|
||||
import System.Plugins
|
||||
import API
|
||||
|
||||
main = do
|
||||
m_v <- dynload "../Plugin.o" ["../api"]
|
||||
[]
|
||||
"resource_dyn"
|
||||
case m_v of
|
||||
LoadFailure _ -> error "didn't compile"
|
||||
LoadSuccess _ (Interface eq) -> do
|
||||
putStrLn $ show $ 1 `eq` 2
|
||||
putStrLn $ show $ 'a' `eq` 'b'
|
||||
|
2
testsuite/dynload/poly/prog/expected
Normal file
2
testsuite/dynload/poly/prog/expected
Normal file
@ -0,0 +1,2 @@
|
||||
True
|
||||
True
|
Reference in New Issue
Block a user