summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authormanuel <manuel@mausz.at>2012-05-14 01:54:29 +0200
committermanuel <manuel@mausz.at>2012-05-14 01:54:29 +0200
commit019b36815c16c44729f25db08395bc0663bb2653 (patch)
tree428593b396bf07cd96e900f06f318fc697dc510d
parent9e3b842e86b1745f294819b61777cd46a53f5648 (diff)
downloadffp-019b36815c16c44729f25db08395bc0663bb2653.tar.gz
ffp-019b36815c16c44729f25db08395bc0663bb2653.tar.bz2
ffp-019b36815c16c44729f25db08395bc0663bb2653.zip
implementing part 1 (eval) of assignment 6
-rw-r--r--AufgabeFFP6.hs19
-rw-r--r--TestAufgabeFFP6.hs22
2 files changed, 41 insertions, 0 deletions
diff --git a/AufgabeFFP6.hs b/AufgabeFFP6.hs
new file mode 100644
index 0000000..ff16ba8
--- /dev/null
+++ b/AufgabeFFP6.hs
@@ -0,0 +1,19 @@
1module AufgabeFFP6
2where
3
4import Data.Array
5
6myfoldl :: [(a -> b -> a)] -> a -> [b] -> a
7myfoldl _ z [] = z
8myfoldl (f:fs) z (x:xs) = myfoldl fs (f z x) xs
9
10myfoldl' :: [(a -> a -> a)] -> [a] -> a
11myfoldl' f (x:xs) = myfoldl f x xs
12
13eval :: Array Int Int -> Array Int (Int -> Int -> Int) -> Int
14eval a b = myfoldl' (elems b) (elems a)
15
16--------------------------------------------------------------------------------
17
18--yield :: Array Int Int -> Int -> [Array Int (Int -> Int -> Int)]
19
diff --git a/TestAufgabeFFP6.hs b/TestAufgabeFFP6.hs
new file mode 100644
index 0000000..86bd75d
--- /dev/null
+++ b/TestAufgabeFFP6.hs
@@ -0,0 +1,22 @@
1module Main where
2
3import Test.HUnit
4import Control.Monad
5import AufgabeFFP6
6import Data.Array
7
8cases1 = TestLabel "eval" $ TestList [
9 TestCase $ assertEqual "eval1" (0)
10 (eval (array (1,3) [(1,1), (2,2), (3,3)]) (array (1,2) [(1,(+)), (2,(-))])),
11 TestCase $ assertEqual "eval2" (5)
12 (eval (array (1,3) [(1,1), (2,2), (3,3)]) (array (1,2) [(1,(*)), (2,(+))])),
13 TestCase $ assertEqual "eval3" (-3)
14 (eval (array (1,3) [(1,1), (2,2), (3,3)]) (array (1,2) [(1,(-)), (2,(*))]))
15 ]
16
17tests :: [Test]
18tests = [cases1]
19
20main = do
21 forM tests $ \test ->
22 runTestTT test