Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Programming > Ml > Destructive Ass...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 1 of 5 Topic 868 of 968
Post > Topic >>

Destructive Assignment in SML

by Rob Hoelz <hoelz@[EMAIL PROTECTED] > Apr 17, 2007 at 09:42 PM

I won't lie; this is for a homework assignment, but I'm not asking it
to be done for me; I just want to know how to accomplish destructive
assingment in ML.  The problem is to construct a function with
memoization, so here's what I have:

local
    val memory = []
in
  fun fastF 0  = 1 | 
    fastF ~1 = 0 | 
    fastF ~2 = 0 | 
    fastF ~3 = 0 | 
    fastF m  =   
        let 
            val result = find (fn (key, value) => key = m) memory
        in  
            if isSome result then
                #2(result)
            else
              let 
                val result = fastF(m-1) + fastF(m-2) + fastF(m-3) -
                    fastF(m-4) 
	      in  
                ((val memory = ((m, result) :: memory)); result)
              end 
        end 

Unfortunately, (val memory = ...) doesn't accomplish what I need; it
causes a syntax error.  Could somone shed some light on how I could
assign to memory?  Thanks!
 




 5 Posts in Topic:
Destructive Assignment in SML
Rob Hoelz <hoelz@[EMAI  2007-04-17 21:42:58 
Re: Destructive Assignment in SML
torbenm@[EMAIL PROTECTED]  2007-04-19 22:24:34 
Re: Destructive Assignment in SML
"Albert Y. C. Lai&qu  2007-04-19 22:25:05 
Re: Destructive Assignment in SML
dbenson@[EMAIL PROTECTED]  2007-04-19 22:25:15 
Re: Destructive Assignment in SML
Vesa Karvonen <vesa.ka  2007-04-19 22:25:40 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 23:48:29 CDT 2008.