The following program, an extention of Tomas program, seems to match the whole of your quotation.

#light
open Microsoft.FSharp.Quotations.Raw

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
let x = 
    <@@
    let Sqr (x:double) = x*x;
    Sqr 3.
    @@>
 
let rec print expr = 
  match expr with
  | Let((var,value), body) -> 
      // Represents: let <var> = <value> in <body>
      printfn "let %s = " var.Text 
      print value
      printfn "\n"
      print body
  | Int32(n) ->
      // Represents a number
      printf "%d" n
  | GenericTopDefnApp <@@ (+) @@> (ty, a::b) ->
      // Represents: <a> + <b>
      print a
      printfn " + "
      print a
  | GenericTopDefnApp <@@ ( * ) @@> (ty, a::b) ->
      // Represents: <a> * <b>
      print a
      printfn " * "
      print a
  | Var(v) ->
      // Represents variable reference
      printf "Var: %s" v.Text
  | Seq(a,b) -> 
      // Represents: <a>; <b> (sequence expression)
      print a
      printfn ";\n"
      print b
  | Lambda(var, body) -> 
      printf "%A" var
      printf " -> "
      print body
  | App(x,y) -> 
      printfn "App"
      print x
      print y
  | Double x -> printfn "Double: %f" x
  | AnyTopDefnUse(def, types) ->
        let _,name = def.Path
        printfn "AnyTopDefnUse: %s" name
  | x -> 
      let t = Reflection.GetTypeInfoOfValue x
      printfn "Unknown value: %A Type: %A" x t 
      
print x
read_line()

One of

By on 8/31/2007 12:53 AM ()

Many thanks Robert,

Got me out of the woods. Looks like I was on the right track but did not think that the order of the patterns would make a difference. Stepping though your working code really helped. Your code produces output ... (which I was roughly expecting)

let Sqr#7683.1 =
x#7679.2 -> Var: x#7679.2 *
Var: x#7679.2
App
Var: Sqr#7683.1Double: 3.000000

My code was producing something roughly along the lines of .... (which kind of confused me)

let Sqr#7683.1 =
x#7679.2 -> App
App
AnyTopDefnUse: op_Multiply
Var: x#7679.2Var: x#7679.2

App
Var: Sqr#7683.1Double: 3.000000

Thanks again

Bart

By on 8/31/2007 10:33 AM ()
IntelliFactory Offices Copyright (c) 2011-2012 IntelliFactory. All rights reserved.
Home | Products | Consulting | Trainings | Blogs | Jobs | Contact Us | Terms of Use | Privacy Policy | Cookie Policy
Built with WebSharper