The code is formatted by adding code tags, like xml tags but with square brackets. I added them to you post, if you reply to that post then you should be able to see the text used.

There currently is no way to define a static field for a type, though this maybe added. All let definition in modules are static so you can make a simple work arround by adding cache as a let definition in the module than contains "expr".

Cheers,
Rob

By on 11/26/2007 1:16 AM ()

Hi. There is still one thing I would like to ask about this matter.

Since it is not currently possible to have static fields as I wanted, a possible work
arrowd would be something like:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
open Microsoft.FSharp.Collection;;

let cache = HashMultiMap<expr,expr>.Create SOME_SIZE;;

type expr =
    | Val of int
    | Add of int * int
    | Sub of int * int
    with
        static member dyn_calc e =
            let e0 = cache.TryFind e in
            match e0 with
            | Some e1 -> e1
            | None -> 
                let e1 = calc e in
                cache.Add (e,e1);
                e1;

        //...

    end;;

But since cache must be defined before type expr I got a compiling error.

Any advice on how can I solve the mutual reference problem?

Thanks.

By on 11/26/2007 9:14 PM ()

I tried

1
let cache = HashMultiMap<_,_>.Create SOME_SIZE;;

and fix the type of dyn_calc with anotation. It compied and worked but with a warning.

By on 11/27/2007 2:11 PM ()

Type members no not necessarily have to been defined with a type, you can define them later using augmentation style syntax:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
#light
open Microsoft.FSharp.Collections

type expr =    
    | Val of int    
    | Add of int * int    
    | Sub of int * int    
    
let cache = HashMultiMap<expr,expr>.Create 11

let calc e = e

type expr with        
    static member dynCalc e =            
        let e0 = cache.TryFind e
        match e0 with            
        | Some e1 -> e1            
        | None ->                 
            let e1 = calc e                
            cache.Add (e,e1)                
            e1
By on 11/26/2007 10:33 PM ()

Really thanks.

Helped a lot.

By on 11/26/2007 10:44 PM ()

Hi Robert,

Thanks very much for the answers.

By on 11/26/2007 1:53 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