Skip to content

fsharp

These are the stories that have been posted to the fsharp category.

F# for Testing and Analysis at Code Camp 11 New England


Published to Rick Minerich's Development Wonderland by Richard Minerich March 26, 2009 20:18

At this Saturday’s Code Camp I’ll be giving a brand new presentation on using F#.  The goal of this presentation is to have those attending leave with an idea of what F# can help them achieve today as well as instill a desire to know more.  This post contains my presentation materials as well as links to additional information on the topics covered.

(Slide and code links will be updated soon.)

 

Presentation Details

F# for Testing and Analytics will be held in the TBC (Technical Briefing Center) at 10:30am.

New England Code Camp 11 Information
Download Presentation Slides
Download Real World Example Code Sample

I’ve been thinking quite a lot lately on the best way to get developers excited about F#.  By focusing less on the language’s details and more on what the language can help achieve I hope to impress upon those attending why F# is worth the effort.  The preliminary structure of the talk is as follows::

  • Introduction
    • Announcing the New England F# User Group 
  • Why F#?
    • Time Savings
    • Readability
    • Code Exploration
    • Robust Software
    • Visual Analytics
  • F# Testing Toolbox
    • xUnit.NET
    • TestDriven.NET and NCover
    • NaturalSpec
    • FsCheck
    • FsStory
  • A Real World Example
    • Exploring the Problem Space
    • Collect, Analyze, Report
    • Visualizing Data

Presentation Influences
John Hughes’s Paper: Why Functional Programming Matters
John Hughes’s Talk: FP – A Secret Weapon for Software Testing
Matthew Podwysocki’s 7 Part Series: Functional Programming Unit Testing

 

Announcing the New England F# User Group 

I’m proud to announce that we will be holding our first New England F# User Group meeting on Monday April 6th, from 6:30pm to 8:30pm.  It will be held at the aptly named Microsoft NERD center.  I hope to see you there.

Visit the F# User Group Homepage for more information.

 

xUnit.NET

“About a year ago it became clear to myself and Brad Wilson that there were some very clear patterns of success (and failure) with the tools we were using for writing tests. Rather than repeating guidance about "do X" or "don't do Y", it seemed like it was the right time to reconsider the framework itself and see if we could codify some of those rules.”

xUnit.NET Homepage

Learn More about xUnit.NET
Matthew Podwysocki’s The Unit Testing Story in F# Revisited
Jim Burger’s Unit testing in F# with xUnit.NET
Harry Pierson’s Practical F# Parsing: Unit Testing

 

TestDriven.NET and NCover

“TestDriven.NET is a zero friction unit testing add-in for Microsoft Visual Studio .NET. The current release of TestDriven.NET supports multiple unit testing frameworks including NUnit, MbUnit and MS Team System and is fully compatible with all versions of the .NET Framework.”

TestDriven.NET Homepage (Includes a free version of NCover)
NCover Homepage

Learn More about TestDriven.NET and NCover
Matthew Podwysocki’s F# + TestDriven.NET + xUnit = Win 
Matthew Podwysocki’s FP Unit Testing Part 4 – Code Coverage

 

NaturalSpec

“The idea of NaturalSpec is to give domain experts the possibility to express their scenarios directly in compilable Unit Test scenarios by using a Domain-specific language (DSL) for Unit Tests. NaturalSpec is completely written in F# – but you don’t have to learn F# to use it. You don’t even have to learn programming at all.”

NaturalSpec Homepage

Learn More about NaturalSpec
Steffen Forkmann’s “Getting Started” with NaturalSpec
Steffen Forkmann’s Testing QuickSort with NaturalSpec
Steffen Forkmann’s Using NaturalSpec to create a spec for C# projects

 

FsCheck

“FsCheck is a tool for testing .NET programs automatically. The programmer provides a specification of the program, in the form of properties which functions, methods or objects should satisfy, and FsCheck then tests that the properties hold in a large number of randomly generated cases.”

FsCheck Homepage

Learn More about FsCheck
Claudio Cherubino’s Random testing in F# with FsCheck
Matthew Podwysocki’s FP Unit Testing Part 2 – QuickCheck and FsCheck
Kurt Schelfthout’s FsChecking dnAnalytics Part 1, Part 2 and Part 3

 

FsStory

“FsStory is a library for writing executable user stories in F#. FsStory enables the developer to write user story scenarios (in Given/When/Then form) in F# code.”

FsStory Homepage

Learn More about FsStory
Gustaf Nilsson Kotte’s Fluent language in FsStory
Gustaf Nilsson Kotte’s FsStory, executable stories in F#

F# and Haskell, Estranged Cousins


Published to Rick Minerich's Development Wonderland by Richard Minerich January 29, 2009 20:24

In this post I compare and contrast Haskell and F#.  It may come as no surprise that with so much shared history they share so much in common.  However, it’s interesting to consider how the perspectives of the languages’ developers play a large role in determining the differences between the languages.

 

A Shared History

As far as the family tree of functional programming is concerned, F# and Haskell are not too distant cousins. haskellandfsharphistory

They both share a very similar syntax as well as a large number of features.  A great example of this is Hindley–Milner type inference. 

ML was the first widely used language to leverage Hindley–Milner for static inferred typing, a feature to which it owes much of it’s success.  However, almost all functional programming languages now also have this feature.  The FP community has always been fast to adopt obviously useful features.  Some other things that fit into this category are garbage collection (Lisp) and lazy evaluation (Lazy ML).

The most obvious difference between Haskell and F# is somewhat easy to infer from this graph: object oriented constructs.  That is to say, OCaml pioneered the use of object oriented data structures in functional programming and F# is it’s direct descendant.  This has made OCaml (and in turn F#) somewhat of a black sheep in the theoretical functional programming world. 

The reason many functional programming theorists dislike objects is because they want a language based on math.  Unlike the majority of the ideas in functional programming, objects don’t have roots in either lambda calculus or category theory.  However, this has not stopped OCaml from being successful.  In fact, quite the opposite. 

The use of objects mitigates one of the largest roadblocks in the path to functional programming adoption by engineers:  the difficulty inherent in organizing large functional programs.  The OCaml language engineers also showed that leveraging the object oriented paradigm did not hamper their ability to use static analysis techniques.  Because of this OCaml approaches the speed of C

While it is not pure, OCaml is almost an ideal compromise between theory and engineering.   Indeed, nothing approaches it in terms of a functional language which fits into the paradigms of the Microsoft .NET framework.  It’s easy to see why Microsoft chose to extend OCaml when building a functional language to bring to it’s software engineering masses.

On the other hand, Haskell is almost the ideal language for academic exploration of functional programming.  The fact that it’s strictly limiting in terms of side effecting and adherence to abstract mathematical concepts means no side effecting surprises.  Also, the fact that it’s a committee language means that if a researcher can get enough support for an idea, they can almost be sure it will be included in the next iteration of the language.

 

Haskell as a Committee Language

Repeat the mantra after me:  Haskell is Lazy; Haskell is Pure; Haskell has Type Classes; Haskell is a Committee Language.

Of all of these, the most defining characteristic of Haskell is that it is a committee language.  It’s an amalgamation of many different goals with no clear vision.  This is at the same time Haskell’s greatest strength and greatest weakness.  While it is the most widely used pure functional programming language, the quirks of committee design are obvious.

Some I ran into within two hours of starting with Haskell:

The first was integer rollover.  Haskell has two integer datatypes: integer and int.  Integer is infinitely sized but can be quite slow to use and due to that, it’s rather infrequently used.  On the other hand int is fast but, just like in C, can roll over. There is no way to check the overflow bit.

So, ints can roll over, I can accept that.  What it implies to me is that speed is more important to Haskell than robustness.  However, this brings me to my second point:  Many basic list operations will throw errors on an empty list.  This seems entirely inconsistent to me. 

I understand that if they didn’t, a logic error would be much more likely to cause an infinite loop in a tail recursive function.  However, this seems completely at odds with the “speed first” definition of an int.  It also means that almost everyone ends up wrapping the default list operations with the Maybe monad.

The third issue was that operations with the float data type are slow.  Real World Haskell suggests always using a double due to the fact that a great deal of focus has gone into optimizing double arithmetic but very little into floats.  This demonstrates another thing that comes about with committee languages: often things as important as optimization of basic data types can fall through the cracks because everyone involved wants to work on more exciting things.

Please don’t misunderstand me here, I really like Haskell.  I’m hard on it because I can see that it has a great deal of unrealized potential.  If Haskell is to be a language used for real software engineering, the committee needs to sit down and think hard about an overarching vision for the project.

 

What is the goal here?

The biggest difference between the world of theorists and the world of engineers is that each group has an entirely different set of concerns.

Theorists want to implement ideas fast so that they can crank out papers fast.  A large part of this is having a language that is very close to math so that implementing ideas directly from the chalkboard is trivial.  As the theory world changes so fast, they don’t often care much about organization or maintainability. 

As the committee responsible for Haskell is mainly made up of theorists, it’s easy to see why the language has taken the direction it has.  It’s a language that is very close to math.  As the lifecycle of most academic code is very short, small implementation details which might cause a reduction in robustness are less important.

Engineers want to minimize time spent maintaining code.  Part of this is having a language that emphasizes safety in that it facilitates catching as many bugs as possible, as early in the process as possible.  Another important part of this is code organization as every moment that is spent trying to find a bug is a moment spent not fixing it.  As the cost of maintaining software generally dwarfs the initial development cost, development speed must take a back seat to testing and organization.

The syntax heavy C# is a great example of this.  It’s slow to write in but provides many constructs for the organization and testing of code.  On top of this a great number of design patterns exist to further categorize substructures in a computer program.  C# is slow to write, but it’s relatively safe and mountains of patterns and best practices have been made to guide it’s developers.

However, we in the software engineering world are in the midst of a crisis.  It turns out that traditional imperative object oriented programs do not lend themselves to heavy parallelization.  Yet, parallelize we must.  We are looking at exponential growth in the number of cores contained in each processor. Because of this we engineers find ourselves at a bit of an impasse.  Those that are looking ahead know…

Engineers will soon want very badly to minimize time spent maintaining parallelized code.  We need our programs to be easy to organize, manage and test.  Yet, as we will soon need to deal with massively parallelized systems, we find many of our ideas about what makes code robust and maintainable are broken.  At the same time, to move to a purely functional language means leaving behind years of thought on how computer programs ought to be constructed, tested and maintained.  Having any pattern, even if it’s wasteful or has many corner cases, is much better than having none.  This is why a hybrid language is so important.

OCaml and F# provide engineers with the set and forget concurrency that comes along with the functional tradition.  At the same time these languages have all of the organizational constructs of object oriented programming as well.  This means that we can continue to use the same types of large scale organizational structures in our programs and also gain the safe parallelism that implicit immutability provides.

 

Conclusion

And so we see that it’s important to consider a language in terms of how it’s creators envisioned it’s use.  Haskell has been developed mainly with research in mind and so is a fantastic research language.  F# has been developed mainly with engineering in mind and so is much better suited for engineering.

In understanding this it’s also easy to see that comparing Haskell to F# is like comparing the tools of a physicist to those of an engineer.  They may have much in common superficially, but they are designed with much different ends in mind.

 

Links

A History of Haskell: Being Lazy with Class
Tutorial: OCaml for Scientific Computation (Contains some history)

Discoveries This Week 01/30/2009


Published to Rick Minerich's Development Wonderland by Richard Minerich January 30, 2009 19:46

The beauty of clean syntax and deep abstraction is an often overlooked feature of functional programming.  As they say, people come to functional programming for the concurrency but stay for the beautiful code (actually, I just made that up).  Also included: POPL 2009, S#arp and functional unit testing.

 

Blog - Matthew Podwysocki’s Series on Functional Unit Testing

In this eight part series Matthew covers unit testing in Haskell from the basics setting up HUnit to the details of writing purely functional tests.

This series is the only place where I’ve seen functional programming unit testing talked about with any significant depth.  While in writing this series Matthew used Haskell, it and F# share much in common and it’s obvious that he worked hard to make his posts apply to both.  I consider it a must read for anyone thinking about taking functional software engineering seriously. 

Although he has finished the series, I hope that in the future he takes some time to focus on unit testing in F# specifically.  I’ve yet to see topics such as mocking or ensuring referential transparency by test covered.

 

Transcription - POPL 2009 Grand Challenges Panel Summary 

This panel was lead by such research giants as Simon Peyton Jones, Xaveir Leroy, Kathryn McKinley, Greg Morrisett and Arvind.  In it they discuss where programming language development is heading and the factors driving us there.  Well worth the read for anyone interested in programming language evolution.

 

Blog - Mark Needham’s F# vs C# vs Java: Collection Parameters

In this post Mark compares list operations in F#, C# and Java.  It’s striking to see how far we have come in terms of clean, concise syntax.  Actually, it seems kind of reminiscent of evolution of man posters.

 

Blog - Jafar Husain’s F#: Real Sharp

When working in F# over a long period it’s easy to forget that one of the best things about it is how it’s concise syntax and deep abstractions make your code so much easier to understand and beautiful to look at.  In his post Jafar reminds us of this by contrasting C# with F# samples.

 

Software – S#arp Architecture Beta 1.0 Available

S#arp Architecture promises to make building web applications much easier by making much of the glue we currently use in ASP.NET web applications obsolete. 

I am a big fan of inversion of control and it is something that comes very natural in functional programming languages.  I hope to see some examples with S#arp Architecture and F# internals at some point in the near future.

Discoveries This Week 01/30/2009


Published to Rick Minerich's Development Wonderland by Richard Minerich January 30, 2009 19:46

The beauty of clean syntax and deep abstraction is an often overlooked feature of functional programming.  As they say, people come to functional programming for the concurrency but stay for the beautiful code (actually, I just made that up).  Also included: POPL 2009, S#arp and functional unit testing.

 

Blog - Matthew Podwysocki’s Series on Functional Unit Testing

In this eight part series Matthew covers unit testing in Haskell from the basics setting up HUnit to the details of writing purely functional tests.

This series is the only place where I’ve seen functional programming unit testing talked about with any significant depth.  While in writing this series Matthew used Haskell, it and F# share much in common and it’s obvious that he worked hard to make his posts apply to both.  I consider it a must read for anyone thinking about taking functional software engineering seriously. 

Although he has finished the series, I hope that in the future he takes some time to focus on unit testing in F# specifically.  I’ve yet to see topics such as mocking or ensuring referential transparency by test covered.

 

Transcription - POPL 2009 Grand Challenges Panel Summary 

This panel was lead by such research giants as Simon Peyton Jones, Xaveir Leroy, Kathryn McKinley, Greg Morrisett and Arvind.  In it they discuss where programming language development is heading and the factors driving us there.  Well worth the read for anyone interested in programming language evolution.

 

Blog - Mark Needham’s F# vs C# vs Java: Collection Parameters

In this post Mark compares list operations in F#, C# and Java.  It’s striking to see how far we have come in terms of clean, concise syntax.  Actually, it seems kind of reminiscent of evolution of man posters.

 

Blog - Jafar Husain’s F#: Real Sharp

When working in F# over a long period it’s easy to forget that one of the best things about it is how it’s concise syntax and deep abstractions make your code so much easier to understand and beautiful to look at.  In his post Jafar reminds us of this by contrasting C# with F# samples.

 

Software – S#arp Architecture Beta 1.0 Available

S#arp Architecture promises to make building web applications much easier by making much of the glue we currently use in ASP.NET web applications obsolete. 

I am a big fan of inversion of control and it is something that comes very natural in functional programming languages.  I hope to see some examples with S#arp Architecture and F# internals at some point in the near future.

Discoveries This Week 02/06/2009


Published to Rick Minerich's Development Wonderland by Richard Minerich February 06, 2009 16:24

Some interesting gems this week.  Revit, Closures and MathTools won the day.  However, I do hope you'll take a look at the IL post as well.

 

Blog – Jeremy Tammik’s Use F# Directly in Revit

In Jeremy’s post he discusses what is initially necessary to get F# and Revit working together.  He also provides a sample of a Revit addin written in F#. 

Revit is Autodesk’s architecture and design studio.  It allows physical engineers to coordinate and play with, design and visualize data while integrating directly with AutoCad.  It also provides a .NET 2.0 API.  Given F#’s support for units as well as it’s concise and mathy style, it makes sense that it would be an ideal language for engineers.

 

Site - WikiBooks FSharp Programming

Before I stumbled upon this site, I had never head of of WikiBooks.  That’s why I was incredibly surprised to find that it has the best online general F# reference around.  It has extensive sections on functional, immutable and imperative programming with rich examples and references to the math behind the ideas presented.  It’s a great site to have at hand for both those learning about the language and those experienced but still needing to occasionally look something small up.

 

StackOverflow -  A practical example of a closure in F#

Learning how to program functionally is much more than just learning some  new ideas and a new syntax.  It comes along with a ton of new jargon, some of which can be quite foreign sounding.  I find that it often turns out that the jargon actually represents a very simple idea and that becomes immediately obvious when discussed with a simple example.

 

Software – FSharp.MathTools

As you might have suspected by its name, MathTools is an extensive set of mathematics libraries for F#.  It provides, among other things, statistical functions, fast fourier transforms, optimization algorithms, Matlab compatibility and extended mathematical notation.  With a little development this combined with VSLab could provide a viable alternative to tools like Matlab while still allowing for collaboration with colleagues.

 

Article – Introduction to IL Assembly Language

It’s the responsibility of any serious programmer to know how how his or her tools work all the way down the chain.  In this relatively short article (given the topic) everything you would need to write a .NET compiler is distilled.  It’s the best reference of it’s kind I’ve seen.

Discoveries This Week 02/06/2009


Published to Rick Minerich's Development Wonderland by Richard Minerich February 06, 2009 16:24

Some interesting gems this week.  Revit, Closures and MathTools won the day.  However, I do hope you'll take a look at the IL post as well.

 

Blog – Jeremy Tammik’s Use F# Directly in Revit

In Jeremy’s post he discusses what is initially necessary to get F# and Revit working together.  He also provides a sample of a Revit addin written in F#. 

Revit is Autodesk’s architecture and design studio.  It allows physical engineers to coordinate and play with, design and visualize data while integrating directly with AutoCad.  It also provides a .NET 2.0 API.  Given F#’s support for units as well as it’s concise and mathy style, it makes sense that it would be an ideal language for engineers.

 

Site - WikiBooks FSharp Programming

Before I stumbled upon this site, I had never head of of WikiBooks.  That’s why I was incredibly surprised to find that it has the best online general F# reference around.  It has extensive sections on functional, immutable and imperative programming with rich examples and references to the math behind the ideas presented.  It’s a great site to have at hand for both those learning about the language and those experienced but still needing to occasionally look something small up.

 

StackOverflow -  A practical example of a closure in F#

Learning how to program functionally is much more than just learning some  new ideas and a new syntax.  It comes along with a ton of new jargon, some of which can be quite foreign sounding.  I find that it often turns out that the jargon actually represents a very simple idea and that becomes immediately obvious when discussed with a simple example.

 

Software – FSharp.MathTools

As you might have suspected by its name, MathTools is an extensive set of mathematics libraries for F#.  It provides, among other things, statistical functions, fast fourier transforms, optimization algorithms, Matlab compatibility and extended mathematical notation.  With a little development this combined with VSLab could provide a viable alternative to tools like Matlab while still allowing for collaboration with colleagues.

 

Article – Introduction to IL Assembly Language

It’s the responsibility of any serious programmer to know how how his or her tools work all the way down the chain.  In this relatively short article (given the topic) everything you would need to write a .NET compiler is distilled.  It’s the best reference of it’s kind I’ve seen.

Image Processing as Sets of Transformations


Published to Rick Minerich's Development Wonderland by Richard Minerich April 28, 2009 00:21

In the image processing world, like most computational problems, we often think our work is composed of only two basic ideas: representation and transformation.  Of course, one may have many layers of both representations of transformations and transformations of representations which can make things appear quite complex at times.

However,  the problem is much more simple than it appears.  This is because a representation can be considered as a transformation from a zero or identity state.  Thus, in writing a symbolic language for image processing, we are left with only a single idea to consider:  transformations.  By composting layers of transformations we can apply image processing techniques in way which is not only bidirectional and platform agnostic but also comes along with a host of other benefits.

 

Let us consider a simplified example of processing an image:

1) We read in a file (representation) and use a codec (transformation) to convert it into a format understood by our API (representation).

2) We then perform some type of algorithm on that data (transformation) which results in some type of output (representation).

3) Finally, via another codec (transformation), another file is saved to disk (representation).

 

In most cases there are a great number of intermediate representations.  Each is a full copy of the previous iteration with whatever changes have been so far applied.  Essentially, the same information is copied over and over again in memory.  We do allow for some kinds of in-place processing, however, this is bad as when the operation has been completed, the previous representation has been destroyed.

 

Instead, what if we batched up sets of transformations?  This could have many benefits:

1) The most obvious benefit is that of parallelization.  Even at the simplest level of functional composition, these transformations could be handed off to a cluster for asynchronous processing or saved for a later batch processing job.

2) With an intermediate symbolic transformation language, processing algorithms could potentially be combined and reduced to produce a single transformation out of many.  This would significantly reduce the processing overhead as well as the number of intermediate memory representations.

3) An intermediate symbolic language which encompassed both codec and processing may make it possible to push the processing transformation through the codec transformation and in so doing no longer need to have any intermediate memory representation.  This could provide significant memory and processing speed time benefit. 

4) The intermediate symbolic language could be saved into the files themselves thus removing the need for the codec to be present on the end machine.  Admittedly, the user would also need the image language interpreter.

5) Instead of applying simple image processing algorithms to an image, the symbolic representation could be appended to the end of the file.  This would be quite similar to layers in practice.  In this way it would be possible to view the image at all stages of transformation.

6) For large or proprietary transformations, the representation could be kept on the internet and either be downloaded or, in the case where the owner did not want to expose their algorithm, a flattened representation could be sent out and a processing delta could be sent back.

 

Conclusion

Of course, when I speak of data I don’t only mean the image itself.  This technique could also be applied to many classes of data or algorithm.  Most notably for us, image metadata.

My initial goal is to build a basic codec representation along with some simple transformations.  Currently, I am researching bidirectional, reversible and declarative languages as examples.  With F# as a base language I believe it will be possible to build something portable to other ML variants.

Discoveries This Week 04/03/2009


Published to Rick Minerich's Development Wonderland by Richard Minerich April 05, 2009 01:42

With the start of our F# User’s Group this next Monday and New England Code Camp 11 last weekend, things have been extremely busy this past week.  Meanwhile, the F# sociocosm is growing at a rapid pace.  This week we have a talk by Don Syme, a look at F# quotations, and finally, some discussion on Seq.unfold.

 

Chris Bowen’s Post, Announcing F# User Group in Cambridge - April 6

A shameless plug here for our new user group.  A big thanks to Chris for helping us find the resources we needed to start out.  Without him this might never have come together.

 

Don Syme’s Talk, F# and functional programming in .NET

As Don Syme is the father of F#, when he speaks the community listens.  In this talk Don focuses on the pleasure and speed inherent in using FP and F#.  He does this by describing the functional methodology and constructs which provide a simpler and more elegant model for building programs.

 

Alex P’s Post, F# quotations at their simplest

A simple example on the surface for sure.  However, if you haven’t seen the power of F#’s language oriented programming features this is sure to be of interest.

For a deeper look at the power of quotations check out Tomáš Petříček’s F# quotations visualizer.  If his past projects are any indication Tom’s upcoming book is a must have for any F# enthusiast.  I preordered a copy just today.

 

Martin Peck’s Post, Solving Problems in C# and F# - Part 2 
(and update)

One of the most fantastic things F# has to offer is the rich functional programming heritage of sequence operations.  To demonstrate how elegant they can make your code, I would like to offer the following alternative F# solution:

let fibs = 
  Seq.unfold (fun (a, b) -> Some( a, (b, a+b) )) (0I, 1I)
Seq.find (fun n -> n >= 10I ** 999I ) fibs

I’m going to take this opportunity to point out the obvious: we have here two lines of F# which does almost exactly the same thing as thirty six of C#.   Now that’s what I call power and elegance.  The unfold function pretty much does exactly what yield was doing before, but implicitly in terms of the unfold function.  The idea of unfold can be confounding at first and so here is a breakdown of how it works:

let fibs =
  Seq.unfold 
    (fun (a, b) -> //generator function, 
//
(a, b) is the previous state Some //Option monad, needed for unfold (a, (b, a + b))) //returned tuple: (value, state)
//or (
first, (second, third)) (0I, 1I) //Initial function state (first, second)

Note that in this version the state of the next two values in the sequence are always pre-calculated.  However, it is easy to avoid this if you instead consider the state in terms of the previous two values: 

let fibs = 
  Seq.unfold (fun (l, l2) -> 
    let n = l + l2 in Some( n, ( n, l ) ))
    (0I, 1I) //(previous, second previous)

If you want to learn more about unfold I recommend checking out:

 

Dustin Campell’s Post, Apples and Oranges

This is the best description of how unfold works I’ve seen to date. 

 
 

F# for Testing and Analysis at Code Camp 11 New England


Published to Rick Minerich's Development Wonderland by Richard Minerich March 27, 2009 22:36

At this Saturday’s Code Camp I’ll be giving a brand new presentation on using F#.  The goal of this presentation is to have those attending leave with an idea of what F# can help them achieve today as well as instill a desire to know more.  This post contains my presentation materials as well as links to additional information on the topics covered.

 

Presentation Details

F# for Testing and Analytics will be held in the TBC (Technical Briefing Center) at 10:30am.

New England Code Camp 11 Information

Download Presentation Slides: F# for Testing and Analysis.pdf

I’ve been thinking quite a lot lately on the best way to get developers excited about F#.  By focusing less on the language’s details and more on what the language can help achieve I hope to impress upon those attending why F# is worth the effort.  The preliminary structure of the talk is as follows::

  • Introduction
    • Announcing the New England F# User Group 
  • Why F#?
    • Time Savings
    • Readability
    • Code Exploration
    • Robust Software
    • Power
  • F# Testing Toolbox
    • xUnit.NET
    • TestDriven.NET and NCover
    • NaturalSpec
    • FsCheck
  • A Real World Example
    • Exploring the Problem Space
    • Collect, Analyze, Report
    • Visualizing Data

Presentation Influences
John Hughes’s Paper: Why Functional Programming Matters
John Hughes’s Talk: FP – A Secret Weapon for Software Testing
Matthew Podwysocki’s 7 Part Series: Functional Programming Unit Testing

 

Announcing the New England F# User Group 

I’m proud to announce that we will be holding our first New England F# User Group meeting on Monday April 6th, from 6:30pm to 8:30pm.  It will be held at the aptly named Microsoft NERD center.  I hope to see you there.

Visit the F# User Group Homepage for more information.

 

xUnit.NET

“About a year ago it became clear to myself and Brad Wilson that there were some very clear patterns of success (and failure) with the tools we were using for writing tests. Rather than repeating guidance about "do X" or "don't do Y", it seemed like it was the right time to reconsider the framework itself and see if we could codify some of those rules.”

xUnit.NET Homepage

Learn More about xUnit.NET
Matthew Podwysocki’s The Unit Testing Story in F# Revisited
Jim Burger’s Unit testing in F# with xUnit.NET
Harry Pierson’s Practical F# Parsing: Unit Testing

 

TestDriven.NET and NCover

“TestDriven.NET is a zero friction unit testing add-in for Microsoft Visual Studio .NET. The current release of TestDriven.NET supports multiple unit testing frameworks including NUnit, MbUnit and MS Team System and is fully compatible with all versions of the .NET Framework.”

TestDriven.NET Homepage (Includes a free version of NCover)
NCover Homepage

Learn More about TestDriven.NET and NCover
Matthew Podwysocki’s F# + TestDriven.NET + xUnit = Win 
Matthew Podwysocki’s FP Unit Testing Part 4 – Code Coverage

 

NaturalSpec

“The idea of NaturalSpec is to give domain experts the possibility to express their scenarios directly in compilable Unit Test scenarios by using a Domain-specific language (DSL) for Unit Tests. NaturalSpec is completely written in F# – but you don’t have to learn F# to use it. You don’t even have to learn programming at all.”

NaturalSpec Homepage

Learn More about NaturalSpec
Steffen Forkmann’s “Getting Started” with NaturalSpec
Steffen Forkmann’s Testing QuickSort with NaturalSpec
Steffen Forkmann’s Using NaturalSpec to create a spec for C# projects

 

FsCheck

“FsCheck is a tool for testing .NET programs automatically. The programmer provides a specification of the program, in the form of properties which functions, methods or objects should satisfy, and FsCheck then tests that the properties hold in a large number of randomly generated cases.”

FsCheck Homepage

Learn More about FsCheck
Claudio Cherubino’s Random testing in F# with FsCheck
Matthew Podwysocki’s FP Unit Testing Part 2 – QuickCheck and FsCheck
Kurt Schelfthout’s FsChecking dnAnalytics Part 1, Part 2 and Part 3

 

FsStory

“FsStory is a library for writing executable user stories in F#. FsStory enables the developer to write user story scenarios (in Given/When/Then form) in F# code.”

FsStory Homepage

Learn More about FsStory
Gustaf Nilsson Kotte’s Fluent language in FsStory
Gustaf Nilsson Kotte’s FsStory, executable stories in F#

Discoveries This Week 03/20/2009


Published to Rick Minerich's Development Wonderland by Richard Minerich March 22, 2009 20:09

This week there seems to be quite a bit of video and audio content to share.  We have a dramatic depiction of the benefits of Units of Measure, Luke Hoban on F#’s feature, Ted Neward talks about F# under the hood and finally a discussion on operator type inference.

 

Video Blog – Could F# have saved the Mars Climate Orbiter?

A fantastic example of how static dimensional analysis of scalar values could prevent an entire class of bugs.   In the past, I’ve talked about what a huge fan I am of the Units of Measure package for F#.  I’m glad that others also see how revolutionary units of measure are. 

Would you want to work in a building or live in a house in which the engineers who built it did not keep track of units?  I don’t think anyone would answer yes.  Similarly, we should not entrust our lives or livelihoods to software in which these very same things are not kept track of.

 

Podcast – SER Episode 129 - F# with Luke Hoban

In this podcast Luke Hoban, the F# program manager, discusses about various aspects of F#. 

Some highlights:

  • Mutability comes along with .NET Framework support.
  • Statically Typed means strong guarantees and so robust systems.
  • FP design in the small for concurrency
  • OO design in the large for scalability
  • Explorative programming via interactive window
  • Influenced heavily by Haskell
  • FP as a technique, not a class of languages

 

Video Blog – dnrTV Show #136: Ted Neward Introduces F#

Ted Neward gives an in-depth presentation on both how F# works under the hood and the general benefits that stem from FP in general.  The examples used are simple but Ted covers them in a very exhaustive way.

Beyond the language and concepts therein, he also has a number of insightful comments about teaching people to use F#.  In particular the idea that F# syntax will be easy to teach but functional programming technique will take years really struck home with me. 

 

Blog – Kalani Thielen’s The F# overload-o-phone

In his post Kalani points out a small but significant logical inconsistency in F#’s type inference system.  The issue seems to stem from the way type inference is handled for basic operators.  Instead of working generically, they each have default types.

From his post:

> (+);;
val it : (int -> int -> int)
> 3.2 + 5.4;;
val it : float = 8.6
> let twice x = x + x;;
> twice 9.4;;
stdin(2,5): error FS0001: This expression has type
    float but is here used with type int.

To get around this, he then goes on to build a function which takes an operator and both arguments.  However, this workaround is completely unnecessary.  You need only to annotate the function’s input and it works without issue.

> let twice (x: double) = x + x
val twice : double –> double
> twice 9.4;;
val it : double = 18.8

Now, it’s important to note that this version of the twice function won’t accept an integer.  In fact, it was a conscious design decision to disallow function overloading in F#.  In both F# and C# all kinds of overloading must be qualified by type.  That is, type methods support argument overloading but free floating functions do not.