Merge branch 'master' of github.com:dopefishh/fp1
authorMart Lubbers <mart@martlubbers.net>
Thu, 5 Feb 2015 20:05:24 +0000 (21:05 +0100)
committerMart Lubbers <mart@martlubbers.net>
Thu, 5 Feb 2015 20:05:24 +0000 (21:05 +0100)
camil/1.1/Start.icl [new file with mode: 0644]
camil/1.1/antwoorden.txt [new file with mode: 0644]
camil/2.1/NotatieFuncties.icl [new file with mode: 0644]
camil/2.1/antwoorden.txt [new file with mode: 0644]
camil/2.11/BottlesOfBeer.icl [new file with mode: 0644]
camil/2.2/VindtDeRedex.icl [new file with mode: 0644]
camil/2.2/antwoorden.txt [new file with mode: 0644]
camil/2.3/MatchStrings.dcl [new file with mode: 0644]
camil/2.3/MatchStrings.icl [new file with mode: 0644]

diff --git a/camil/1.1/Start.icl b/camil/1.1/Start.icl
new file mode 100644 (file)
index 0000000..b56a850
--- /dev/null
@@ -0,0 +1,18 @@
+module Start\r
+\r
+import StdEnv\r
+\r
+Start = expr11\r
+\r
+expr0 = "Hello World!"\r
+expr1 = "Hello " +++ "World!"\r
+expr2 = 5\r
+expr3 = 5.5\r
+//expr4 = 5 + 5.5\r
+expr5 = [1..10]\r
+expr6 = (expr1,expr2,expr3,expr5)\r
+//expr7 = [expr1,expr2,expr3,expr5]\r
+expr8 = [1,3..10]\r
+expr9 = ['a'..'z']\r
+expr10 = ['a','c'..'z']\r
+expr11 = ['Hello World!']
\ No newline at end of file
diff --git a/camil/1.1/antwoorden.txt b/camil/1.1/antwoorden.txt
new file mode 100644 (file)
index 0000000..3a223e2
--- /dev/null
@@ -0,0 +1,29 @@
+Antwoorden opgave 1.1
+Camil Staps (s4498062)
+
+1.     Het programma wordt gecompileerd.
+2.     Het programma wordt uitgevoerd.
+3.     De data types van de variabelen worden automatisch achterhaald door de IDE (en hoeven dus niet expliciet te  worden gegeven door de programmeur)
+
+expr1  "Hello World!"
+       De strings worden geconcateneerd
+expr2  5
+       Dit is een Int waarde
+expr3  5.5
+       Dit is een Real waarde
+expr4  Type error; cannot unify types Real and Int
+       Dat is omdat + is niet gedefinieerd voor Real met Int
+expr5  [1,2,3,4,5,6,7,8,9,10]
+       Dit is een korte schrijfwijze voor deze lijst ([min..max])
+expr6  ("Hello World!",5,5.5,[1,2,3,4,5,6,7,8,9,10])
+       Een tupeltje
+expr7  Type error; cannot unify types [Int] and Real
+       Dat is omdat elementen van een lijst hetzelfde type moeten hebben, en dat hier niet het geval is
+expr8  [1,3,5,7,9]
+       Een andere vorm van expr5 waarmee in het begin wordt aangegeven wat de interval is
+expr9  ['a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z']
+       Een lijst van karakters
+expr10 ['a','c','e','g','i','k','m','o','q','s','u','w','y']
+       Een combinatie van expr9 en expr8
+expr11 ['H','e','l','l','o',' ','W','o','r','l','d','!']
+       Blijkbaar wordt ['...'] als lijst van karakters beschouwd
diff --git a/camil/2.1/NotatieFuncties.icl b/camil/2.1/NotatieFuncties.icl
new file mode 100644 (file)
index 0000000..bab2054
--- /dev/null
@@ -0,0 +1,39 @@
+module NotatieFuncties\r
+\r
+import StdEnv\r
+\r
+f1                     :: Int\r
+f1                     = 1 + 5\r
+\r
+f2                     :: Int\r
+f2                     = (+) 1 5\r
+\r
+f3                     :: Int Int -> Int\r
+f3 m n\r
+| m < n                = m\r
+| otherwise    = n\r
+\r
+f4                     :: String Int -> String\r
+f4 s n\r
+| n <= 0       = ""\r
+| otherwise    = s +++ f4 s (n-1)\r
+\r
+f5                     :: Int Int -> Int\r
+f5 x 0         = x\r
+f5 x y         = f5 y (x rem y)\r
+\r
+f6                     :: (Int,Int) -> Int\r
+f6 x           = fst x + snd x\r
+\r
+f7                     :: (a,b) -> (b,a)\r
+f7 (a,b)       = (b,a)\r
+\r
+f8                     :: (a,a) -> (a,a)\r
+f8 x           = f7 (f7 x)\r
+\r
+//Start                = (f3 1 5, f3 4 3, f3 6 6)\r
+//Start                = f4 "ab" 4\r
+//Start                = (f5 13 5, f5 8 4, f5 20 20)\r
+//Start                = f6 (2,3)\r
+//Start                = f7 (5,7)\r
+Start          = f8 (5,7)\r
diff --git a/camil/2.1/antwoorden.txt b/camil/2.1/antwoorden.txt
new file mode 100644 (file)
index 0000000..c0c98d6
--- /dev/null
@@ -0,0 +1,8 @@
+f1     5+1=6; constant
+f2     Reverse polix notation voor f1; zelfde functie dus
+f3     Geeft de kleinste van twee integers terug
+f4     Herhaalt s n keer
+f5     Geeft de ggd van x en y met Euclides' algoritme
+f6     Geeft de optelling x+y voor een tupel (x,y)
+f7     Flipt de twee elementen van een tupel
+f8     Flipt de twee elementen van een tupel twee keer (heeft geen effect)
diff --git a/camil/2.11/BottlesOfBeer.icl b/camil/2.11/BottlesOfBeer.icl
new file mode 100644 (file)
index 0000000..70628a1
--- /dev/null
@@ -0,0 +1,21 @@
+module BottlesOfBeer\r
+\r
+import StdEnv\r
+\r
+Start = [(fst_line x +++ "\n" +++ snd_line x +++ "\n\n") \\ x <- [99,98..0]]\r
+\r
+fst_line :: Int -> String\r
+fst_line n = btl n True +++ wall +++ ", " +++ btl n False +++ " of beer."\r
+\r
+snd_line :: Int -> String\r
+snd_line 0 = "Go to the store and buy some more, " +++ btl 99 False +++ wall +++ "."\r
+snd_line n = "Take one down and pass it around, " +++ btl (n-1) False +++ wall +++ "."\r
+\r
+btl :: Int Bool -> String\r
+btl 0 True = "No more bottles"\r
+btl 0 False = "no more bottles"\r
+btl 1 b = "1 bottle"\r
+btl n b = toString n +++ " bottles"\r
+\r
+wall :: String\r
+wall = " of beer on the wall"
\ No newline at end of file
diff --git a/camil/2.2/VindtDeRedex.icl b/camil/2.2/VindtDeRedex.icl
new file mode 100644 (file)
index 0000000..c7ec330
--- /dev/null
@@ -0,0 +1,17 @@
+module VindtDeRedex\r
+\r
+import StdEnv\r
+\r
+e1 = 42\r
+\r
+e2 = 1 + 125 * 8 / 10 - 59\r
+\r
+e3 = not True || True && False\r
+\r
+e4 =  1 + 2  ==  6 - 3\r
+\r
+e5 = "1 + 2" == "6 - 3"\r
+\r
+e6 = "1111 + 2222" == "1111" +++ " + " +++ "2222"\r
+\r
+Start = e6\r
diff --git a/camil/2.2/antwoorden.txt b/camil/2.2/antwoorden.txt
new file mode 100644 (file)
index 0000000..413465c
--- /dev/null
@@ -0,0 +1,42 @@
+e1 = 42        Is elementair
+
+e2 = 1 + 125 * 8 / 10 - 59
+e2 = (1 + ((125 * 8) / 10)) - 59
+            -------
+e2 = (1 + (1000 / 10)) - 59
+           ---------
+e2 = (1 + 100) - 59
+      -------
+e2 = 101 - 59
+     --------
+e2 = 42
+
+e3 = not True || True && False
+e3 = (not True) || (True && False)
+      --------
+e3 = False || (True && False)
+               -------------
+e3 = False || False
+     --------------
+e3 = False
+
+e4 = 1 + 2 == 6 - 3
+e4 = (1 + 2) == (6 - 3)
+      -----
+e4 = 3 == (6 - 3)
+           -----
+e4 = 3 == 3
+e4 = True
+
+e5 = "1 + 2" == "6 - 3"
+     ------------------
+e5 = False
+
+e6 = "1111 + 2222" == "1111" +++ " + " +++ "2222"
+e6 = "1111 + 2222" == (("1111" +++ " + ") +++ "2222")
+                       -----------------
+e6 = "1111 + 2222" == ("1111 + " +++ "2222")
+                       --------------------
+e6 = "1111 + 2222" == "1111 + 2222"
+     ------------------------------
+e6 = True
diff --git a/camil/2.3/MatchStrings.dcl b/camil/2.3/MatchStrings.dcl
new file mode 100644 (file)
index 0000000..527447c
--- /dev/null
@@ -0,0 +1,8 @@
+definition module MatchStrings\r
+\r
+head                   ::        String -> Char\r
+tail                   ::        String -> String\r
+is_gelijk              :: String String -> Bool\r
+is_deelstring  :: String String -> Bool\r
+is_deel                        :: String String -> Bool\r
+is_match               :: String String -> Bool\r
diff --git a/camil/2.3/MatchStrings.icl b/camil/2.3/MatchStrings.icl
new file mode 100644 (file)
index 0000000..17859ae
--- /dev/null
@@ -0,0 +1,48 @@
+implementation module MatchStrings\r
+\r
+import StdEnv\r
+\r
+head                           :: String -> Char\r
+head ""                                = abort "head uitgevoerd op lege string"\r
+head s                         = s.[0]\r
+\r
+tail                           :: String -> String\r
+tail ""                                = abort "tail uitgevoerd op lege string"\r
+tail s                         = s % (1, size s - 1)\r
+\r
+is_gelijk                      :: String String -> Bool\r
+is_gelijk "" ""                = True\r
+is_gelijk a ""         = False\r
+is_gelijk "" b                 = False\r
+is_gelijk a b          = (head a == head b) && (is_gelijk (tail a) (tail b))\r
+\r
+is_deelstring          :: String String -> Bool\r
+is_deelstring "" b     = True\r
+is_deelstring a ""     = False\r
+is_deelstring a b      = is_gelijk a (b % (0, size a - 1)) || is_deelstring a (tail b)\r
+\r
+is_deel                                :: String String -> Bool\r
+is_deel "" b           = True\r
+is_deel a ""           = False\r
+is_deel a b                    = head a == head b && is_deel (tail a) (tail b) || is_deel a (tail b)\r
+\r
+is_match                       :: String String -> Bool\r
+is_match "" ""         = True\r
+is_match "" b          = False\r
+is_match "*" ""                = True\r
+is_match a ""          = False\r
+is_match a b           = (head a == '.' || head a == head b) && is_match (tail a) (tail b) || head a == '*' && (is_match a (tail b) || is_match (tail a) b)\r
+\r
+//Start                                = (head pink_floyd, tail pink_floyd)\r
+//Start                                = is_gelijk     "" " "\r
+//Start                                = is_deelstring "there"          pink_floyd\r
+//Start                                = is_deelstring "there"          marillion\r
+//Start                                = is_deel       "there"          marillion\r
+//Start                                = is_deel       "she and her"    pink_floyd\r
+//Start                                = is_deel       radiohead        pink_floyd\r
+//Start                                = is_match      "*.here*.here*." pink_floyd\r
+//Start                                = is_match      ".here.here."    pink_floyd\r
+\r
+pink_floyd                     = "Is there anybody in there?"\r
+marillion                      = "Just for the record"\r
+radiohead                      = "There there"\r