From b354f2bd98af1f28eb7ac161917e6ae3b290c5dc Mon Sep 17 00:00:00 2001 From: Francesco Minnocci Date: Wed, 4 May 2022 22:35:42 +0200 Subject: [PATCH] Add lab8 --- esperimenti/Program.fs | 3 +++ lab8/Program.fs | 35 +++++++++++++++++++++++++++++++++++ ludo/Program.fs | 2 +- 3 files changed, 39 insertions(+), 1 deletion(-) create mode 100644 lab8/Program.fs diff --git a/esperimenti/Program.fs b/esperimenti/Program.fs index 8b41b49..62620ca 100644 --- a/esperimenti/Program.fs +++ b/esperimenti/Program.fs @@ -21,3 +21,6 @@ printfn "%b" (isPippo(numOfStringsContainingAs [|"a";"a";"a";"a"|] |> numeroPipp printfn "%b" (isPippo(numOfStringsContainingAs [|"a";"a";"a"|] |> numeroPippo)) printfn "%b" (isPippo(parolaPippo("pipo"))) printfn "%b" (isPippo(parolaPippo("pippo"))) + +let s = Seq.initInfinite (fun s -> s*s) +Seq.toList (Seq.take 10 s) diff --git a/lab8/Program.fs b/lab8/Program.fs new file mode 100644 index 0000000..9db0e3b --- /dev/null +++ b/lab8/Program.fs @@ -0,0 +1,35 @@ +// identificatori +type ide = string + +type aexp = + | AEint of int + | AEplus of (aexp * aexp) + | AEminus of (aexp * aexp) + | AElet of (ide * aexp * aexp) + | AEide of ide + +let rec aexp_to_string : aexp -> string = + fun e -> + match e with + AEint i -> sprintf "%d" i + | AEplus (e,f) -> sprintf "(%s + %s)" (aexp_to_string e) (aexp_to_string f) + | AEminus (e,f) -> sprintf "(%s - %s)" (aexp_to_string e) (aexp_to_string f) + | AElet (x, e, f) -> + Printf.sprintf "(let %s = %s in %s)" x (aexp_to_string e) (aexp_to_string f) + | AEide (x) -> x + +// error handling +let unbound_identifier_error ide = + failwith (Printf.sprintf "unbound identifier %s" ide) + +// semantic domains +type eval = int +type dval = eval // denotable and expressible values coincide + +let eval_to_string : eval -> string = + fun e -> Printf.sprintf "%d" e + +// ambiente +type env = ide -> dval + +let empty = fun v -> unbound_identifier_error v diff --git a/ludo/Program.fs b/ludo/Program.fs index 360e254..9708eb6 100644 --- a/ludo/Program.fs +++ b/ludo/Program.fs @@ -36,7 +36,7 @@ let rec sumFirstFun f k = let rec fold g f k1 k2 z = if (k2 < k1) then z else g (fold g f (k1+1) k2 z) (f(k1)) -> + let sum x y = x + y let double x = 2*x