Update examples

This commit is contained in:
Don Stewart
2005-09-03 04:45:14 +00:00
parent 5321754614
commit dff0363224
421 changed files with 19 additions and 9 deletions

View File

@ -0,0 +1,45 @@
--
-- Copyright (c) 2004 Don Stewart - http://www.cse.unsw.edu.au/~dons
-- GPL version 2 or later (see http://www.gnu.org/copyleft/gpl.html)
--
--
-- | Runplugs: use hs-plugins to run a Haskell expression under
-- controlled conditions.
--
import System.Eval.Haskell (unsafeEval)
import Data.Maybe (isJust, fromJust)
import Control.Monad (when)
import System.Exit (exitWith, ExitCode(ExitSuccess))
import System.IO (getContents, putStrLn)
import System.Posix.Resource (setResourceLimit,
Resource(ResourceCPUTime),
ResourceLimits(ResourceLimits),
ResourceLimit(ResourceLimit))
rlimit = ResourceLimit 3
context = prehier ++ datas ++ qualifieds ++ controls
prehier = ["Char", "List", "Maybe", "Numeric", "Random" ]
qualifieds = ["qualified Data.Map as M", "qualified Data.Set as S"]
datas = map ("Data." ++) [
"Bits", "Bool", "Char", "Dynamic", "Either",
"Graph", "Int", "Ix", "List",
"Maybe", "Ratio", "Tree", "Tuple", "Typeable", "Word"
]
controls = map ("Control." ++) ["Monad", "Monad.Reader", "Monad.Fix", "Arrow"]
main = do
setResourceLimit ResourceCPUTime (ResourceLimits rlimit rlimit)
s <- getContents
when (not . null $ s) $ do
s <- unsafeEval ("(take 2048 (show ("++s++")))") context
when (isJust s) (putStrLn (fromJust s))
exitWith ExitSuccess

View File

@ -0,0 +1,30 @@
GHCFLAGS= -Onot $(GHC_EXTRA_OPTS)
PKGFLAGS= -package posix
PKGFLAGS+= -package plugins
all: build
build:
@$(GHC) $(GHCFLAGS) $(PKGFLAGS) $(EXTRAFLAGS) Main.hs -o runplugs
include ../../../config.mk
check: build
@(if [ -f "expected" ] ;\
then \
actual_out="/tmp/hs-plugins-actual.out.$$$$" ;\
diff_out="/tmp/hs-plugins.diff.$$$$" ;\
cat test.in | ./runplugs > $$actual_out 2>&1 || true ;\
diff -u expected $$actual_out > $$diff_out || true ;\
if [ -s "$$diff_out" ] ; then \
echo "failed with:" ;\
cat "$$diff_out" | sed '1,3d' ;\
else \
echo "ok." ;\
fi ;\
rm $$actual_out ;\
else \
cat test.in | ./runplugs 2>&1 || true ;\
fi)
clean:
rm -rf *.hi *.o *~ *.dep ./runplugs
include ../../../config.mk

View File

@ -0,0 +1 @@
453973694165307953197296969697410619233826

View File

@ -0,0 +1 @@
let fibs = 1 : 1 : zipWith (+) fibs (tail fibs) in fibs !! 200