Update examples
This commit is contained in:
5
testsuite/eval/eval1/Main.hs
Normal file
5
testsuite/eval/eval1/Main.hs
Normal file
@ -0,0 +1,5 @@
|
||||
|
||||
import System.Eval.Haskell
|
||||
|
||||
main = do i <- eval "1 + 6 :: Int" [] :: IO (Maybe Int)
|
||||
if isJust i then putStrLn $ show (fromJust i) else return ()
|
2
testsuite/eval/eval1/Makefile
Normal file
2
testsuite/eval/eval1/Makefile
Normal file
@ -0,0 +1,2 @@
|
||||
TOP=../../..
|
||||
include ../../eval.mk
|
1
testsuite/eval/eval1/expected
Normal file
1
testsuite/eval/eval1/expected
Normal file
@ -0,0 +1 @@
|
||||
7
|
6
testsuite/eval/eval2/Main.hs
Normal file
6
testsuite/eval/eval2/Main.hs
Normal file
@ -0,0 +1,6 @@
|
||||
import System.Eval.Haskell
|
||||
|
||||
main = do m_s <- eval "map toUpper \"haskell\"" ["Data.Char"]
|
||||
case m_s of
|
||||
Nothing -> putStrLn "typechecking failed"
|
||||
Just s -> putStrLn s
|
2
testsuite/eval/eval2/Makefile
Normal file
2
testsuite/eval/eval2/Makefile
Normal file
@ -0,0 +1,2 @@
|
||||
TOP=../../..
|
||||
include ../../eval.mk
|
1
testsuite/eval/eval2/expected
Normal file
1
testsuite/eval/eval2/expected
Normal file
@ -0,0 +1 @@
|
||||
HASKELL
|
38
testsuite/eval/eval3/Main.hs
Normal file
38
testsuite/eval/eval3/Main.hs
Normal file
@ -0,0 +1,38 @@
|
||||
{-# OPTIONS -cpp #-}
|
||||
--
|
||||
-- Should evaluate to '3', unless something goes wrong.
|
||||
--
|
||||
-- Not so bad to use AltData, as it is already derived for all the basic
|
||||
-- types. Then, just replace deriving Typeable, with hand-derived
|
||||
-- instance of Typeable (see hs-plugins/testsuite/eval/eval_fn1/Poly.hs
|
||||
--
|
||||
--
|
||||
|
||||
#include "../../../config.h"
|
||||
|
||||
import System.Eval
|
||||
import AltData.Dynamic
|
||||
|
||||
main = do
|
||||
a <- return $ toDyn (3::Integer)
|
||||
|
||||
-- so, we try to compile a function that takes a dyn.
|
||||
-- looks like with GHC 6.4, we need to make sure the package.confs work:
|
||||
m_b <- unsafeEval_ "\\dyn -> fromDyn dyn (7 :: Integer)"
|
||||
["AltData.Dynamic"]
|
||||
[ ]
|
||||
[ ]
|
||||
[]
|
||||
|
||||
case m_b of
|
||||
Left s -> mapM_ putStrLn s
|
||||
Right b -> putStrLn $ show (b a :: Integer) -- now apply it
|
||||
|
||||
{-
|
||||
-- should work, but doesn't. type check fails
|
||||
-- (due to static vs dynamic typing issue)
|
||||
|
||||
m_b <- unsafeEval_ "\\dyn -> fromMaybe (7 :: Int) (fromDynamic dyn)"
|
||||
["Data.Dynamic","Data.Maybe"] [] []
|
||||
-}
|
||||
|
2
testsuite/eval/eval3/Makefile
Normal file
2
testsuite/eval/eval3/Makefile
Normal file
@ -0,0 +1,2 @@
|
||||
TOP=../../..
|
||||
include ../../eval.mk
|
1
testsuite/eval/eval3/expected
Normal file
1
testsuite/eval/eval3/expected
Normal file
@ -0,0 +1 @@
|
||||
3
|
9
testsuite/eval/eval_/Main.hs
Normal file
9
testsuite/eval/eval_/Main.hs
Normal file
@ -0,0 +1,9 @@
|
||||
|
||||
import System.Eval.Haskell
|
||||
|
||||
main = do i <- eval_ "Just (7 :: Int)"
|
||||
["Maybe"]
|
||||
["-fglasgow-exts"]
|
||||
[]
|
||||
[] :: IO (Either [String] (Maybe (Maybe Int)))
|
||||
print i
|
2
testsuite/eval/eval_/Makefile
Normal file
2
testsuite/eval/eval_/Makefile
Normal file
@ -0,0 +1,2 @@
|
||||
TOP=../../..
|
||||
include ../../eval.mk
|
1
testsuite/eval/eval_/expected
Normal file
1
testsuite/eval/eval_/expected
Normal file
@ -0,0 +1 @@
|
||||
Right (Just (Just 7))
|
10
testsuite/eval/eval_fn/Main.hs
Normal file
10
testsuite/eval/eval_fn/Main.hs
Normal file
@ -0,0 +1,10 @@
|
||||
--
|
||||
-- lambda abstraction!
|
||||
--
|
||||
--
|
||||
-- needs unsafeEval because eval has a broken Dynamic check
|
||||
--
|
||||
import System.Eval.Haskell
|
||||
|
||||
main = do fn <- unsafeEval "(\\x -> (x,x::Int))" [] :: IO (Maybe (Int -> (Int,Int)))
|
||||
when (isJust fn) $ putStrLn $ show $ (fromJust fn) 7
|
2
testsuite/eval/eval_fn/Makefile
Normal file
2
testsuite/eval/eval_fn/Makefile
Normal file
@ -0,0 +1,2 @@
|
||||
TOP=../../..
|
||||
include ../../eval.mk
|
1
testsuite/eval/eval_fn/expected
Normal file
1
testsuite/eval/eval_fn/expected
Normal file
@ -0,0 +1 @@
|
||||
(7,7)
|
15
testsuite/eval/eval_fn1/Main.hs
Normal file
15
testsuite/eval/eval_fn1/Main.hs
Normal file
@ -0,0 +1,15 @@
|
||||
{-# OPTIONS -fglasgow-exts #-}
|
||||
--
|
||||
-- polymorphic eval!
|
||||
--
|
||||
|
||||
module Main where
|
||||
|
||||
import Poly
|
||||
import System.Eval.Haskell
|
||||
|
||||
main = do m_f <- eval "Fn (\\x y -> x == y)" ["Poly"]
|
||||
when (isJust m_f) $ do
|
||||
let (Fn f) = fromJust m_f
|
||||
putStrLn $ show (f True True)
|
||||
putStrLn $ show (f 1 2)
|
2
testsuite/eval/eval_fn1/Makefile
Normal file
2
testsuite/eval/eval_fn1/Makefile
Normal file
@ -0,0 +1,2 @@
|
||||
TOP=../../..
|
||||
include ../../eval.mk
|
16
testsuite/eval/eval_fn1/Poly.hs
Normal file
16
testsuite/eval/eval_fn1/Poly.hs
Normal file
@ -0,0 +1,16 @@
|
||||
{-# OPTIONS -cpp -fglasgow-exts #-}
|
||||
module Poly where
|
||||
|
||||
import AltData.Typeable
|
||||
|
||||
data Fn = Fn {fn :: forall t. Eq t => t -> t -> Bool}
|
||||
|
||||
--
|
||||
-- ignore type inside the Fn... is this correct?
|
||||
--
|
||||
instance Typeable Fn where
|
||||
#if __GLASGOW_HASKELL__ >= 603
|
||||
typeOf _ = mkTyConApp (mkTyCon "Poly.Fn") []
|
||||
#else
|
||||
typeOf _ = mkAppTy (mkTyCon "Poly.Fn") []
|
||||
#endif
|
2
testsuite/eval/eval_fn1/expected
Normal file
2
testsuite/eval/eval_fn1/expected
Normal file
@ -0,0 +1,2 @@
|
||||
True
|
||||
False
|
2
testsuite/eval/foreign_eval/Makefile
Normal file
2
testsuite/eval/foreign_eval/Makefile
Normal file
@ -0,0 +1,2 @@
|
||||
TOP=../../..
|
||||
include ../../foreign.mk
|
1
testsuite/eval/foreign_eval/README
Normal file
1
testsuite/eval/foreign_eval/README
Normal file
@ -0,0 +1 @@
|
||||
run a string of Haskell code from a C program.
|
0
testsuite/eval/foreign_eval/dont_test
Normal file
0
testsuite/eval/foreign_eval/dont_test
Normal file
1
testsuite/eval/foreign_eval/expected
Normal file
1
testsuite/eval/foreign_eval/expected
Normal file
@ -0,0 +1 @@
|
||||
10946
|
16
testsuite/eval/foreign_eval/main.c
Normal file
16
testsuite/eval/foreign_eval/main.c
Normal file
@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "EvalHaskell.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int *p;
|
||||
hs_init(&argc, &argv);
|
||||
p = hs_eval_i("let fibs = 1:1:zipWith (+) fibs (tail fibs) in fibs !! 20 :: Int");
|
||||
if (p == NULL)
|
||||
printf("failed!\n");
|
||||
else
|
||||
printf("%d\n",*p);
|
||||
hs_exit();
|
||||
return 0;
|
||||
}
|
2
testsuite/eval/foreign_eval1/Makefile
Normal file
2
testsuite/eval/foreign_eval1/Makefile
Normal file
@ -0,0 +1,2 @@
|
||||
TOP=../../..
|
||||
include ../../foreign.mk
|
0
testsuite/eval/foreign_eval1/dont_test
Normal file
0
testsuite/eval/foreign_eval1/dont_test
Normal file
1
testsuite/eval/foreign_eval1/expected
Normal file
1
testsuite/eval/foreign_eval1/expected
Normal file
@ -0,0 +1 @@
|
||||
10946
|
16
testsuite/eval/foreign_eval1/main.c
Normal file
16
testsuite/eval/foreign_eval1/main.c
Normal file
@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "EvalHaskell.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
char *p;
|
||||
hs_init(&argc, &argv);
|
||||
p = hs_eval_s("show $ let fibs = 1:1:zipWith (+) fibs (tail fibs) in fibs !! 20");
|
||||
if (p == NULL)
|
||||
printf("failed!\n");
|
||||
else
|
||||
printf("%s\n",p);
|
||||
hs_exit();
|
||||
return 0;
|
||||
}
|
2
testsuite/eval/foreign_should_fail/Makefile
Normal file
2
testsuite/eval/foreign_should_fail/Makefile
Normal file
@ -0,0 +1,2 @@
|
||||
TOP=../../..
|
||||
include ../../foreign.mk
|
0
testsuite/eval/foreign_should_fail/dont_test
Normal file
0
testsuite/eval/foreign_should_fail/dont_test
Normal file
2
testsuite/eval/foreign_should_fail/expected
Normal file
2
testsuite/eval/foreign_should_fail/expected
Normal file
@ -0,0 +1,2 @@
|
||||
<eval>:1: parse error on input `in'
|
||||
failed!
|
1
testsuite/eval/foreign_should_fail/expected.604
Normal file
1
testsuite/eval/foreign_should_fail/expected.604
Normal file
@ -0,0 +1 @@
|
||||
failed!
|
1
testsuite/eval/foreign_should_fail/expected.605
Normal file
1
testsuite/eval/foreign_should_fail/expected.605
Normal file
@ -0,0 +1 @@
|
||||
failed!
|
16
testsuite/eval/foreign_should_fail/main.c
Normal file
16
testsuite/eval/foreign_should_fail/main.c
Normal file
@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "EvalHaskell.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int *p;
|
||||
hs_init(&argc, &argv);
|
||||
p = hs_eval_i("show $ case 1 + 2 in{-wrong-} x -> x");
|
||||
if (p == NULL)
|
||||
printf("failed!\n");
|
||||
else
|
||||
printf("%d\n",*p);
|
||||
hs_exit();
|
||||
return 0;
|
||||
}
|
2
testsuite/eval/foreign_should_fail_illtyped/Makefile
Normal file
2
testsuite/eval/foreign_should_fail_illtyped/Makefile
Normal file
@ -0,0 +1,2 @@
|
||||
TOP=../../..
|
||||
include ../../foreign.mk
|
4
testsuite/eval/foreign_should_fail_illtyped/expected
Normal file
4
testsuite/eval/foreign_should_fail_illtyped/expected
Normal file
@ -0,0 +1,4 @@
|
||||
Couldn't match `Int' against `[Char]'
|
||||
Expected type: Int
|
||||
Inferred type: [Char]
|
||||
failed!
|
1
testsuite/eval/foreign_should_fail_illtyped/expected.604
Normal file
1
testsuite/eval/foreign_should_fail_illtyped/expected.604
Normal file
@ -0,0 +1 @@
|
||||
failed!
|
1
testsuite/eval/foreign_should_fail_illtyped/expected.605
Normal file
1
testsuite/eval/foreign_should_fail_illtyped/expected.605
Normal file
@ -0,0 +1 @@
|
||||
failed!
|
16
testsuite/eval/foreign_should_fail_illtyped/main.c
Normal file
16
testsuite/eval/foreign_should_fail_illtyped/main.c
Normal file
@ -0,0 +1,16 @@
|
||||
#include <stdio.h>
|
||||
|
||||
#include "EvalHaskell.h"
|
||||
|
||||
int main(int argc, char *argv[])
|
||||
{
|
||||
int *p;
|
||||
hs_init(&argc, &argv);
|
||||
p = hs_eval_i("\"an ill-typed string\"");
|
||||
if (p == NULL)
|
||||
printf("failed!\n");
|
||||
else
|
||||
printf("%d\n",*p);
|
||||
hs_exit();
|
||||
return 0;
|
||||
}
|
16
testsuite/eval/unsafeidir/Main.hs
Normal file
16
testsuite/eval/unsafeidir/Main.hs
Normal file
@ -0,0 +1,16 @@
|
||||
|
||||
import System.Plugins.Make
|
||||
import System.Eval.Haskell
|
||||
|
||||
main = do make "a/Extra.hs" []
|
||||
|
||||
i <- unsafeEval_ "show (Just (1 + 6 :: Int)) ++ extra"
|
||||
["Data.Maybe", "Extra"]
|
||||
["-ia"] -- no make flags
|
||||
[] -- no package.confs
|
||||
["a"] -- include paths to load from
|
||||
:: IO (Either [String] String)
|
||||
|
||||
case i of
|
||||
Right i -> putStrLn $ show i
|
||||
Left es -> mapM_ putStrLn es
|
2
testsuite/eval/unsafeidir/Makefile
Normal file
2
testsuite/eval/unsafeidir/Makefile
Normal file
@ -0,0 +1,2 @@
|
||||
TOP=../../..
|
||||
include ../../eval.mk
|
3
testsuite/eval/unsafeidir/a/Extra.hs
Normal file
3
testsuite/eval/unsafeidir/a/Extra.hs
Normal file
@ -0,0 +1,3 @@
|
||||
module Extra where
|
||||
|
||||
extra = "an extra value"
|
1
testsuite/eval/unsafeidir/expected
Normal file
1
testsuite/eval/unsafeidir/expected
Normal file
@ -0,0 +1 @@
|
||||
"Just 7an extra value"
|
Reference in New Issue
Block a user