main
Francesco Minnocci 3 years ago
parent 777133c94a
commit b354f2bd98
Signed by: BachoSeven
GPG Key ID: 2BE4AB7FDAD828A4

@ -21,3 +21,6 @@ printfn "%b" (isPippo(numOfStringsContainingAs [|"a";"a";"a";"a"|] |> numeroPipp
printfn "%b" (isPippo(numOfStringsContainingAs [|"a";"a";"a"|] |> numeroPippo)) printfn "%b" (isPippo(numOfStringsContainingAs [|"a";"a";"a"|] |> numeroPippo))
printfn "%b" (isPippo(parolaPippo("pipo"))) printfn "%b" (isPippo(parolaPippo("pipo")))
printfn "%b" (isPippo(parolaPippo("pippo"))) printfn "%b" (isPippo(parolaPippo("pippo")))
let s = Seq.initInfinite (fun s -> s*s)
Seq.toList (Seq.take 10 s)

@ -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

@ -36,7 +36,7 @@ let rec sumFirstFun f k =
let rec fold g f k1 k2 z = let rec fold g f k1 k2 z =
if (k2 < k1) then z if (k2 < k1) then z
else g (fold g f (k1+1) k2 z) (f(k1)) else g (fold g f (k1+1) k2 z) (f(k1))
>
let sum x y = x + y let sum x y = x + y
let double x = 2*x let double x = 2*x

Loading…
Cancel
Save