aboutsummaryrefslogtreecommitdiff
path: root/Semestr 3/pf/lista1
diff options
context:
space:
mode:
authorFranciszek Malinka <franciszek.malinka@gmail.com>2021-02-25 14:42:55 +0100
committerFranciszek Malinka <franciszek.malinka@gmail.com>2021-02-25 14:42:55 +0100
commit9477dbe667f250ecd23f8fc0d56b942191526421 (patch)
treea4b50c9a726f415f835f5311c11c5d66e95f688c /Semestr 3/pf/lista1
parent1968c1e590077bd51844eacfac722d7963848cb8 (diff)
Stare semestry, niepoukladane
Diffstat (limited to 'Semestr 3/pf/lista1')
-rw-r--r--Semestr 3/pf/lista1/a.outbin0 -> 21950 bytes
-rw-r--r--Semestr 3/pf/lista1/lista1bin0 -> 823616 bytes
-rw-r--r--Semestr 3/pf/lista1/lista1.cmibin0 -> 2188 bytes
-rw-r--r--Semestr 3/pf/lista1/lista1.cmobin0 -> 1407 bytes
-rw-r--r--Semestr 3/pf/lista1/lista1.ml70
-rw-r--r--Semestr 3/pf/lista1/zad6.ml37
6 files changed, 107 insertions, 0 deletions
diff --git a/Semestr 3/pf/lista1/a.out b/Semestr 3/pf/lista1/a.out
new file mode 100644
index 0000000..7fcdd98
--- /dev/null
+++ b/Semestr 3/pf/lista1/a.out
Binary files differ
diff --git a/Semestr 3/pf/lista1/lista1 b/Semestr 3/pf/lista1/lista1
new file mode 100644
index 0000000..8ce2f26
--- /dev/null
+++ b/Semestr 3/pf/lista1/lista1
Binary files differ
diff --git a/Semestr 3/pf/lista1/lista1.cmi b/Semestr 3/pf/lista1/lista1.cmi
new file mode 100644
index 0000000..f2f5745
--- /dev/null
+++ b/Semestr 3/pf/lista1/lista1.cmi
Binary files differ
diff --git a/Semestr 3/pf/lista1/lista1.cmo b/Semestr 3/pf/lista1/lista1.cmo
new file mode 100644
index 0000000..801e852
--- /dev/null
+++ b/Semestr 3/pf/lista1/lista1.cmo
Binary files differ
diff --git a/Semestr 3/pf/lista1/lista1.ml b/Semestr 3/pf/lista1/lista1.ml
new file mode 100644
index 0000000..f8f585f
--- /dev/null
+++ b/Semestr 3/pf/lista1/lista1.ml
@@ -0,0 +1,70 @@
+(* Zadanie 1 *)
+
+let a1 f g x = x |> g |> f
+let ff (a : 'a -> 'b) (b : 'c -> 'a) = fun x -> a (b x)
+
+let a2 a b = a
+let a3 a b = if a = b then a else a
+
+(* Zadanie 2 *);;
+let rec x y = x y;;
+
+(* Nie mozna bo etykieta b nie zostala nigdzie nalozona to jak ma byc sciagnieta? *)
+
+(* Zadanie 3 *);;
+
+
+let hd s = s 0
+let tl s = fun x -> s (x + 1)
+let add value s = fun x -> s x + value
+let map f s = fun x -> x |> s |> f
+let map2 f s1 s2 =
+ fun x -> let a = s1 x and b = s2 x in f a b
+let replace n a s =
+ fun x -> if x mod n = 0 then a else s x
+let take n s =
+ fun x -> n*x |> s
+let rec scan f a s =
+ fun x ->
+ if x = 0 then f a (s 0)
+ else f ((scan f a s) (x - 1)) (s x)
+let rec tabulate ?(l=0) r s =
+ if l = r then [s r]
+ else s l :: tabulate ~l:(l + 1) r s
+let s1 x = x + 1
+let s2 x = x * x
+
+(* Zadanie 4 *)
+
+let ctrue a b = a
+let cfalse a b = b
+let cand f1 f2 a b = f1 (f2 a b) b
+let cor f1 f2 a b = f1 a (f2 a b)
+let cbool_of_bool b = if b then ctrue else cfalse
+let bool_of_cbool f = f true false
+
+
+(* Zadanie 5 *)
+
+let zero f x = x
+let succ fn = fun f x -> fn f (f x)
+let add f1 f2 = fun f x -> f1 f (f2 f x)
+let mul f1 f2 = fun f x -> (f1 (f2 f)) x
+let is_zero f =
+ let g x = x + 1
+ in if (f g 0) = 0 then ctrue else cfalse
+let rec cnum_of_int = function
+ | 0 -> zero
+ | n -> succ (cnum_of_int (n - 1))
+
+let int_of_cnum f = f (fun x -> x + 1) 0
+
+let one = succ zero
+let two = succ one
+let three = succ two
+let four = succ three
+let five = succ four
+
+let func x = x * 2
+
+(* Zadanie 6 *) \ No newline at end of file
diff --git a/Semestr 3/pf/lista1/zad6.ml b/Semestr 3/pf/lista1/zad6.ml
new file mode 100644
index 0000000..46e7f6d
--- /dev/null
+++ b/Semestr 3/pf/lista1/zad6.ml
@@ -0,0 +1,37 @@
+type cbool = { cbool : 'a. 'a -> 'a -> 'a }
+type cnum = { cnum : 'a. ('a -> 'a) -> 'a -> 'a }
+
+
+let even n =
+ { cbool = fun tt ff -> fst (n.cnum (fun (a, b) -> (b, a)) (tt, ff))}
+
+
+let ctrue =
+ { cbool = fun a b -> a}
+let cfalse =
+ { cbool = fun a b -> b}
+let cand f1 f2 a b = f1.cbool (f2.cbool a b) b
+let cor f1 f2 a b = f1.cbool a (f2.cbool a b)
+let cbool_of_bool b = if b then ctrue else cfalse
+let bool_of_cbool f = f.cbool true false
+
+let zero = { cnum = fun f x -> x }
+let succ fn = { cnum = fun f x -> fn.cnum f (f x) }
+let add f1 f2 = { cnum = fun f x -> f1.cnum f (f2.cnum f x) }
+let mul f1 f2 = { cnum = fun f x -> f1.cnum (f2.cnum f) x }
+(* let is_zero f = *)
+let rec cnum_of_int = function
+ | 0 -> zero
+ | n -> succ (cnum_of_int (n - 1))
+let is_zero f =
+ let g x = x + 1
+ in if (f.cnum g 0) = 0 then ctrue else cfalse
+let int_of_cnum f = f.cnum (fun x -> x + 1) 0
+
+let one = succ zero
+let two = succ one
+let three = succ two
+let four = succ three
+let five = succ four
+
+let func x = x * 2 \ No newline at end of file