The following does the trick:

1
2
3
4
5
6
7
let Cached2 f =


  let c = Cached (fun (a, b) -> f a b)


  fun a b -> c (a,b)
By on 7/1/2009 2:26 PM ()

Thanks!Makes sense, strange it worked differently before.

By on 7/1/2009 11:03 PM ()

funny, but what does this caching mean?

(I needed to intend the Cached sq and Cached2 plus under the let (so one indentation left))

same thing as outputted:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
  let sqr x =

    printfn "%d * %d" x x

    x * x

  sqr 3 |> printfn "%d"

  plus x y =

     printfn "%d + %d" x y

     x + y

  plus 1 3 |> printfn "%d"

thought letting me peek into the outer let's however also:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
    let sqr =

      let sqr x =

        printfn "%d * %d" x x

        x * x

      sqr

    sqr 3 |> printfn "%d"

    let plust =

      let plust x y =

        printfn "%d + %d" x y

        x + y

      plust

    plust 1 3 |> printfn "%d"

works like the cached version. (didn't know yet that you can make a call directly to a let defined inside an outer let !?)

don't mind just trying to understand F#, I reckon the reason to Cache things aren't shown here, and you'll retrieve it someplace else afterwards.

(I moved to IE8.0 yesterday, for some reason this gives a different interface, not allowing me to keep the intended indentation in the above)

By on 7/2/2009 12:10 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