1 people like it.

Solution to the problem mentioned at : http://professor-fish.blogspot.com/2011/01/tiny-bit-of-denotational-semantics.html

Solution to the problem mentioned at : http://professor-fish.blogspot.com/2011/01/tiny-bit-of-denotational-semantics.html

 1: 
 2: 
 3: 
 4: 
 5: 
 6: 
 7: 
 8: 
 9: 
10: 
11: 
type Expr =  Const of int
            | Add of (Expr * Expr)
            | Exit of Expr

let rec eval (e:Expr) (f:int -> int) = 
    match e with 
    | Const x -> f x
    | Add (a,b) -> eval b (fun z -> z + eval a f)
    | Exit x -> eval x (fun z -> z)
            
let a = eval (Add (Exit (Add (Exit (Const 1), Const 10)), Exit( Add( Const 8, Const 10) ))) (fun a -> a)
union case Expr.Const: int -> Expr
Multiple items
val int : value:'T -> int (requires member op_Explicit)

Full name: Microsoft.FSharp.Core.Operators.int

--------------------
type int = int32

Full name: Microsoft.FSharp.Core.int

--------------------
type int<'Measure> = int

Full name: Microsoft.FSharp.Core.int<_>
union case Expr.Add: (Expr * Expr) -> Expr
type Expr =
  | Const of int
  | Add of (Expr * Expr)
  | Exit of Expr

Full name: Script.Expr
union case Expr.Exit: Expr -> Expr
val eval : e:Expr -> f:(int -> int) -> int

Full name: Script.eval
val e : Expr
val f : (int -> int)
val x : int
val a : Expr
val b : Expr
val z : int
val x : Expr
val a : int

Full name: Script.a
val a : int
Raw view New version

More information

Link:http://fssnip.net/49
Posted:6 years ago
Author:Ankur Dhama
Tags: denotational semantics , expression evaluation