Using the NAG Library for .NET from F#

NAG is currently running a beta test of a NAG Library for .NET. One noticeable feature of the comments received so far is the relatively large number of users interfacing to the library from F# rather than C# or VB.NET.

F# is a functional programming language derived from OCAML, which in turn has a shared ancestry with the Standard ML programming language that I used over 20 years ago while working on theorem proving systems at Manchester university…

The .NET area of the NAG website has been updated with a discussion article and example programs showing how to write console applications and windows form applications from F#.

Using small wrappers one may provide functional interfaces to the NAG library that work well with the interactive loop of the F# interpreter, allowing calls to the NAG library with essentially no syntactic overhead. The following is a complete F# expression (integrating the sin function between 0 and pi) with the results being echoed back by the F# top level, using a read-eval-print interface which should be familiar to users of lisp, or MATLAB and similar systems.

// using myd01ah
> myd01ah Math.Sin (0.0,Math.PI) 0.01 1000 ;;
val it : d01ahresults = {result = 2.0;
                         npts = 7;
                         relerr = 0.0006944567037;
                         ifail = 0;}

The fsharp article has several more examples, together with a discussion of the differences between F# and C# interfaces. Feel free to use use the comment feature here on the blog to discuss any issues related to calling the NAG library from F#.


Popular posts from this blog

Implied Volatility using Python's Pandas Library

C++ wrappers for the NAG C Library

ParaView, VTK files and endianness