You can use a "ref" to a function to dynamically later change its behavior in FSI. Here is an example, that demonstrates the issue you're describing (redefining 'f' is not picked up by 'perform') as well as the easy workaround (add a layer of mutable indirection, use a ref to a function and mutate the ref and have perform call through the ref).

> let f() =
- printfn "hi";;

val f : unit -> unit

> let mutable g = ref f;;

val mutable g : (unit -> unit) ref

> let perform() =
- for i in 1..3 do
- (!g) ()
- ;;

val perform : unit -> unit

> perform();;
hi
hi
hi
val it : unit = ()
> let f() =
- printfn "new";;

val f : unit -> unit

> perform();;
hi
hi
hi
val it : unit = ()
> g := f;;
val it : unit = ()
> perform();;
new
new
new
val it : unit = ()
>

By on 11/23/2008 11:21 AM ()

Hi,

Thanks, it works:) This interactive mode is nice, lots of stuff one can do with it, and some of them are pretty hacky:)

By on 11/23/2008 12:18 PM ()
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