I made a mistake--then lookasideTable should be [n] .

On page 188, Listing 8-5 I had a problem:

let memoizeAndPermitDiscard f =<?XML:NAMESPACE PREFIX = O />

let lookasideTable = new System.Collections.Generic.Dictionary<_, _>()

{ new Table<_, _> with

member t.Item

with get(n) =

if lookasideTable.ContainsKey(n)

then lookasideTable.[n]

else let res = f n // Error 2 ‘let’

lookasideTable.Add(n, res) // Error 1 ‘lookasideTable’

res

member t.Discard() =

lookasideTable.Clear() }

Error 1 incomplete construct at or before this point in expression

Error 2 error in the return expression for this 'let'. Possible incorrect indentation.

By on 2/1/2009 7:36 AM ()

If I put the let res = f n on the next line, it seems to work fine:

let memoizeAndPermitDiscard f =
let lookasideTable = new System.Collections.Generic.Dictionary<_, _>()
{ new Table<_, _> with
member t.Item
with get(n) =
if lookasideTable.ContainsKey(n)
then lookasideTable.[n]
else
let res = f n
lookasideTable.Add(n, res)
res
member t.Discard() =
lookasideTable.Clear() }

By on 2/1/2009 7:42 AM ()

Thank-you!

By on 2/1/2009 7:56 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