Import hs-plugins cvs

This commit is contained in:
Don Stewart
2005-04-24 08:51:33 +00:00
commit 887fa59389
494 changed files with 23721 additions and 0 deletions

View File

@ -0,0 +1,5 @@
import Eval.Haskell
main = do i <- eval "1 + 6 :: Int" [] :: IO (Maybe Int)
if isJust i then putStrLn $ show (fromJust i) else return ()

View File

@ -0,0 +1,2 @@
TOP=../../..
include ../../eval.mk

View File

@ -0,0 +1 @@
7

View File

@ -0,0 +1,6 @@
import Eval.Haskell
main = do m_s <- eval "map toUpper \"haskell\"" ["Data.Char"]
case m_s of
Nothing -> putStrLn "typechecking failed"
Just s -> putStrLn s

View File

@ -0,0 +1,2 @@
TOP=../../..
include ../../eval.mk

View File

@ -0,0 +1 @@
HASKELL

View File

@ -0,0 +1,42 @@
{-# 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/examples/eval/eval_fn1/Poly.hs
--
--
#include "../../../config.h"
import Eval.Haskell
import AltData.Dynamic
-- import Data.Dynamic
pkgconf = TOP ++ "/plugins.conf.inplace"
main = do
a <- return $ toDyn (3::Int)
m_b <- unsafeEval_ "\\dyn -> fromMaybe (7 :: Int) (fromDyn dyn)"
["AltData.Dynamic","Data.Maybe"] -- imports
[ "-package-conf "++pkgconf , "-package altdata" ]
[ pkgconf ]
[]
{-
-- 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"] [] []
-}
case m_b of
Left s -> mapM_ putStrLn s
Right b -> putStrLn $ show (b a :: Int)

View File

@ -0,0 +1,2 @@
TOP=../../..
include ../../eval.mk

View File

@ -0,0 +1 @@
3

View File

@ -0,0 +1,9 @@
import Eval.Haskell
main = do i <- eval_ "Just (7 :: Int)"
["Maybe"]
["-fglasgow-exts"]
[]
[] :: IO (Either [String] (Maybe (Maybe Int)))
print i

View File

@ -0,0 +1,2 @@
TOP=../../..
include ../../eval.mk

View File

@ -0,0 +1 @@
Right (Just (Just 7))

View File

@ -0,0 +1,10 @@
--
-- lambda abstraction!
--
--
-- needs unsafeEval because eval has a broken Dynamic check
--
import Eval.Haskell
main = do fn <- unsafeEval "(\\(x::Int) -> (x,x))" [] :: IO (Maybe (Int -> (Int,Int)))
when (isJust fn) $ putStrLn $ show $ (fromJust fn) 7

View File

@ -0,0 +1,2 @@
TOP=../../..
include ../../eval.mk

View File

@ -0,0 +1 @@
(7,7)

View File

@ -0,0 +1,15 @@
{-# OPTIONS -fglasgow-exts #-}
--
-- polymorphic eval!
--
module Main where
import Poly
import 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)

View File

@ -0,0 +1,2 @@
TOP=../../..
include ../../eval.mk

View 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

View File

@ -0,0 +1,2 @@
True
False

View File

@ -0,0 +1,2 @@
TOP=../../..
include ../../foreign.mk

View File

@ -0,0 +1 @@
run a string of Haskell code from a C program.

View File

@ -0,0 +1 @@
10946

View 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;
}

View File

@ -0,0 +1,2 @@
TOP=../../..
include ../../foreign.mk

View File

@ -0,0 +1 @@
10946

View 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;
}

View File

@ -0,0 +1,2 @@
TOP=../../..
include ../../foreign.mk

View File

@ -0,0 +1,2 @@
<eval>:1: parse error on input `in'
failed!

View File

@ -0,0 +1 @@
failed!

View 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;
}

View File

@ -0,0 +1,2 @@
TOP=../../..
include ../../foreign.mk

View File

@ -0,0 +1,4 @@
Couldn't match `Int' against `[Char]'
Expected type: Int
Inferred type: [Char]
failed!

View File

@ -0,0 +1 @@
failed!

View 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;
}

View File

@ -0,0 +1,16 @@
import Plugins.Make
import 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

View File

@ -0,0 +1,2 @@
TOP=../../..
include ../../eval.mk

View File

@ -0,0 +1,3 @@
module Extra where
extra = "an extra value"

View File

@ -0,0 +1 @@
"Just 7an extra value"