How to get working variables out of a function in F# -


i have function in f# , like:

let myfunction x =      let workingvariable1 = x + 1     let workingvariable2 = workingvariable1 + 1     let y = workingvariable2 + 1     y 

basically, myfunction takes input x , returns y. however, in process of calculation, there few working variables (intermediate variables), , due nature of work (civil engineering), need report intermediate results. how should store working variables of function ?

if understand correctly, there several options:

let myfunction1 x =      let workingvariable1 = x + 1     let workingvariable2 = workingvariable1 + 1     let y = workingvariable2 + 1     y,workingvariable1,workingvariable2  myfunction1 2 |> printfn "%a"  type onetype()=     member val y = 0 get,set     member val wv1 = 0 get,set     member val wv2 = 0 get,set      override this.tostring() =         sprintf "y: %d; wv1: %d; wv2: %d\n" this.y this.wv1 this.wv2  let myfunction2 x =      let workingvariable1 = x + 1     let workingvariable2 = workingvariable1 + 1     let y = workingvariable2 + 1     new onetype(y=y,wv1=workingvariable1,wv2=workingvariable2)  myfunction2 2 |> printfn "%a" 

out:

(5, 3, 4) y: 5; wv1: 3; wv2: 4 

http://ideone.com/eynwym

in first function uses tuple: https://msdn.microsoft.com/en-us/library/dd233200.aspx

the second native data type. https://msdn.microsoft.com/en-us/library/dd233205.aspx


Comments

Popular posts from this blog

javascript - AngularJS custom datepicker directive -

javascript - jQuery date picker - Disable dates after the selection from the first date picker -