// sum_tuple declaration let sum_tuple (a,b) = a + b;; // sum_curried declaration let sum_curried a b = a + b;; // sum_ref declaration let sum_ref (a,b,r) = r := a + b;; // sum_byref declaration let sum_byref (a,b,r:byref) = r <- a + b;; // Simple sum examples let r1 = sum_tuple (1,2);; let r2 = sum_curried 1 2;; let rr3 = ref 0;; sum_ref (1,2,rr3);; let r3 = !rr3;; let mutable r4 = 0;; sum_byref(1,2,&r4);; printfn "r4=%i" r4;; // composing sum examples (functional) let c1=sum_tuple (sum_tuple(1,1),sum_tuple(2,2));; let c2=sum_curried (sum_curried 1 1) (sum_curried 2 2);; // composing sum examples (imperative) let r3a = ref 0;; let r3b = ref 0;; let r3c = ref 0;; sum_ref (1,1,r3a);; sum_ref (2,2,r3b);; sum_ref (!r3a,!r3b,r3c);; let c3 = !r3c;; let mutable r4a = 0;; let mutable r4b = 0;; let mutable c4 = 0;; sum_byref (1,1,&r4a);; sum_byref (2,2,&r4b);; sum_byref (r4a,r4b,&c4);; printfn "c4=%i" c4;; // mysum declaration and use let mysum a b = let r = ref 0 sum_ref(a,b,r) !r ;; let c5=mysum(mysum 1 1) (mysum 2 2);; // NAG Library reference for fsi #if INTERACTIVE #I @"c:\Program Files\NAG\NAG Library for .NET" #r "NagLibrary32.dll" #endif open System open NagLibrary // a00ac example printfn "Have a NAG licence: %b" (A00.a00ac()) // d01ah example: direct call let if1 = ref 0 let mutable npts=0 let relerr= ref 0.0 let f x = Math.Sin(x:double) let nlimit=1000 let ff= D01.D01AH_F(f) let result1 = D01.d01ah(0.0,Math.PI,0.01,&npts,relerr,ff,nlimit, if1);; printfn "!if1=%i" !if1;; printfn "npts=%i" npts;; printfn "!relerr=%f" !relerr; // d01ah example: returning a tuple let (result2,if2) = D01.d01ah(0.0,Math.PI,0.01,&npts, relerr,(fun x -> f x),nlimit);; printfn "npts=%i" npts;; printfn "!relerr=%f" !relerr;; // declaration of myd01ah: curried, returning a record type d01ahresults = { result: float ; npts: int ; relerr: float; ifail: int } let myd01ah f interval epsr nlimit = let ff=D01.D01AH_F(f) let (a,b) = interval let npts = ref 0 let relerr = ref 0.0 let ifl = ref 0 let result = D01.d01ah(a,b,epsr,npts,relerr,ff,nlimit,ifl) {result= result; npts= !npts;relerr= !relerr;ifail= !ifl} ;; // using myd01ah let _ = myd01ah Math.Sin (0.0,Math.PI) 0.01 1000 ;; // declaration of mye04ab: curried, returning a record type e04abresults = { minimum: float ; x: float; bounds: (float*float); iter: int; ifail: int } let mye04ab f interv e1 e2 mc = let a,b = interv let ra = ref a let rb = ref b let fx = ref 0.0 let x = ref 0.0 let mcr = ref mc let ifr = ref 0 E04.e04ab((fun x res -> res <- f x ), ref e1, ref e2, ra, rb, mcr ,x, fx ,ifr) {minimum = !fx; x = !x;bounds = (!ra,!rb); iter= !mcr; ifail = !ifr} ;; // using mye04ab let _ = mye04ab (fun x -> (Math.Sin x) / x) (3.0,5.0) 0.0 0.0 30 ;;