Tools such as NCover and the Haskell Program Coverage tool, it can ensure our honesty when it comes to tests, and we get a glaring reminder when we don't. These tools, when combined with our traditional xUnit and property-based tests with saturation test generation can be a satisfying experience. We've now covered the creation and combination of traditional xUnit tests with property-based tests and how to leverage code coverage as a tool for refining. There is still more to be covered in this series which includes refactoring.
In the functional programming world, we have two main ways of testing our code, either through the traditional xUnit tests or the more powerful QuickCheck property-based tests. Each of these are powerful in their own right, but made more powerful when combined into a single unit. When combined we have the power of integrating them into our CI process through some of the build/package tools in our tool belt.
Avalda FPGA Developer compiles "quoted" F# programs. Quotations are a feature in F# in which you wrap an F# expression in the quotation operators "<@@" and "@@>" so that the expression is treated like data and can be manipulated as such. The Avalda FPGA Developer api then allows the quoted expression to be translated to an XML encoding suitable for the core Avalda FPGA Developer compiler tool. So, write the following program and go to "Build" -> "Build GCDTutorial" to build a dll called gcdtutorial.dll: #light "off" namespace GCDTutorial type GCD = class static member gcdprogram = <@@ let rec gcd( (m : int), (n : int) ) = if m = 0 then n else gcd( n % m, m) in () @@> end
If you have C# code and just try to transliterate it directly to F#, the F# code you wind up with is unlikely to be idiomatic or "good". Nevertheless, when you are new to a language (F#), it is sometimes useful to know how to transliterate from a well-known language (C#) for those cases where you just don't know the idioms yet, but don't want that to prevent you from making progress. So today's blog entry takes the general form of "here's some C# code, how do I write the same thing in F#". It is intended to be used as a reference or as casual reading to discover some little-used or lesser-known F# syntax/operators/functions. Today's blog entry covers only code that goes inside a method body, so you won't find anything about declaring classes or using namespaces here. Instead I will be covering the following bits of C#: * casts * operators * expressions * statements and show a way to transliterate those C# forms into F#.
FParsec is an F# adaptation of Parsec. It can parse context-sensitive, infinite look-ahead grammars. The basic idea behind combinator parsing is to compose parsers for higher-level grammar expressions from simple atomic parsers. A parser combinator library provides those predefined atomic parsers and the means to combine them into larger units. In the case of FParsec all parsers are F# functions, functions that can be combined with higher-level functions, so-called "combinators". The parser combinator approach as implemented by FParsec has a number of advantages * Power. Since parsers are first-class values within the language, users can draw on the full power of F# to implement their parsers. * Extensibility. FParsec has a modular design that is very amenable to extensions. No matter how complicated your grammar is, you will always be able to parse it * Quality of error messages. Parsers implemented with FParsec generate intelligible error messages