<?xml version="1.0" encoding="UTF-8"?>
<?xml-stylesheet type="text/xsl" media="screen" href="/~d/styles/atom10full.xsl"?><?xml-stylesheet type="text/css" media="screen" href="http://feeds.feedburner.com/~d/styles/itemcontent.css"?><feed xmlns="http://www.w3.org/2005/Atom" xmlns:openSearch="http://a9.com/-/spec/opensearch/1.1/" xmlns:georss="http://www.georss.org/georss" xmlns:gd="http://schemas.google.com/g/2005" xmlns:feedburner="http://rssnamespace.org/feedburner/ext/1.0" gd:etag="W/&quot;CUMCR3Y-fCp7ImA9WxNUF0Q.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430</id><updated>2009-11-09T11:04:26.854-08:00</updated><title>Random Ravings of a Red Headed Code Monkey</title><subtitle type="html">This blog will focus on Software Engineering, best practices and how they can be leveraged to bridge the gap between business and technology.</subtitle><link rel="http://schemas.google.com/g/2005#feed" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/posts/default" /><link rel="alternate" type="text/html" href="http://bloggemdano.blogspot.com/" /><link rel="hub" href="http://pubsubhubbub.appspot.com/" /><link rel="next" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default?start-index=26&amp;max-results=25&amp;redirect=false&amp;v=2" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email></author><generator version="7.00" uri="http://www.blogger.com">Blogger</generator><openSearch:totalResults>30</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>25</openSearch:itemsPerPage><link rel="self" href="http://feeds.feedburner.com/BloggemDano" type="application/atom+xml" /><feedburner:emailServiceId>BloggemDano</feedburner:emailServiceId><feedburner:feedburnerHostname>http://feedburner.google.com</feedburner:feedburnerHostname><atom10:link xmlns:atom10="http://www.w3.org/2005/Atom" rel="hub" href="http://pubsubhubbub.appspot.com" /><entry gd:etag="W/&quot;CUMCR3Y9fSp7ImA9WxNUF0Q.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-7163019021136006367</id><published>2009-11-09T11:01:00.000-08:00</published><updated>2009-11-09T11:04:26.865-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-11-09T11:04:26.865-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="F#" /><title>F# Firestarter in Nashville, TN on 11/14/2009</title><content type="html">Checkout the upcoming F# Firestarter in Nashville, TN&amp;nbsp;on 11/14/2009. It's going to be a great day of learning, exploring, hacking, and socializing. &lt;br /&gt;
We would very much like to launch a functional programming user's group out of this event, so come on out and share your thoughts and insights.&amp;nbsp; You won't want to miss it. &lt;br /&gt;
&lt;br /&gt;
You can register for the event at&lt;a href="http://fsharpfirestarter.eventbrite.com/"&gt; http://fsharpfirestarter.eventbrite.com/&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
More information can be found at &lt;a href="http://fsharpfirestarter.blogspot.com/"&gt;http://fsharpfirestarter.blogspot.com/&lt;/a&gt;.&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-7163019021136006367?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/7163019021136006367/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=7163019021136006367" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/7163019021136006367?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/7163019021136006367?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/XDJr7gCZcj4/f-firestarter-in-nashville-on-11142009.html" title="F# Firestarter in Nashville, TN on 11/14/2009" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2009/11/f-firestarter-in-nashville-on-11142009.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkAGSHo6fip7ImA9WxNXFEk.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-7978317625484843437</id><published>2009-10-01T17:52:00.000-07:00</published><updated>2009-10-01T17:52:09.416-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-10-01T17:52:09.416-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Development" /><category scheme="http://www.blogger.com/atom/ns#" term="Architecture" /><category scheme="http://www.blogger.com/atom/ns#" term="Principles and Standards" /><title>Development Principles and Standards</title><content type="html">Several months ago I was asked to lead a fairly large development&amp;nbsp;project that involved efforts from multiple consultant and offshore development groups.&amp;nbsp; One of the first things that I did was draft a development principles and standards document to ensure that all groups were on the same page.&amp;nbsp; The following is a slightly revised version of that document.&amp;nbsp; This information is not new or extremly profound; however, I thought it might be beneficial to some.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Development Principles and Standards &lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
There are several core principles and standards that are essential to the development of any solution. These principles and standards are necessary to ensure maintainability of the solution as well as successful, cost effective implementations of future customers that wish to take advantage of the product offering. &lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Reusability &lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
Reusability is of prime importance as it relates to the development of the different aspects of a solution. The expectation is that all system functionality should be constructed so that new customers can be setup within the solution with no development. In addition, all functionality should be constructed in a manner that allows other systems to be able to interact with the solution with no internal system development. &lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Extensibility and Maintainability &lt;/strong&gt;&lt;br /&gt;
&lt;br /&gt;
There are multiple principles that should be followed to increase the extensibility and maintainability of the solution. &lt;br /&gt;
&lt;br /&gt;
• Separation of Concerns (SoC) - This generally implies separation of UI, service, domain, and data access/persistence layers as well as abstraction of contracts/interfaces from implementation specifics. This allows for clear delineation of functionality and ensures that any type of updates to the solution can be accomplished quickly and with little to no unexpected ramifications.&lt;br /&gt;
&lt;br /&gt;
• Single Responsibility Principle (SRP) – This principle states that each component, class, method, and/or function should only be responsible for a single piece of functionality. Another way to state this is that each distinct code block should only have a single reason to change. This reduces the potential for accidently causing an unexpected consequence when modifying a particular feature or piece of functionality. &lt;br /&gt;
&lt;br /&gt;
• Don’t Repeat Yourself (DRY) – In order to make a solution extensible and maintainable, code and/or logic should not be duplicated. Failure to adhere to this principle increases both development time and the likelihood of errors. &lt;br /&gt;
&lt;br /&gt;
• Self Documented Code – In order for a solution to be maintainable, it must be very easy to determine the intent of any specific piece of code. One of the best ways to accomplish this goal is to ensure that all code is as descriptive as possible by using identifier, method, function, and class names that clearly define intent. &lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Automated Tests and Testability&lt;/strong&gt; &lt;br /&gt;
&lt;br /&gt;
Functionality should be wrapped in automated tests. Ideally the solution would be developed using a test-first approach; however, it is acceptable to utilize a test-after approach as long as the majority of functionality is under test by the time of delivery. In addition to the “unit tests” (tests around each individual method), functional tests should be written to ensure that the overall behavior works as expected. Finally, all tests should be maintained during future development endeavors and run before “check-in” and before each deployment. These tests accomplish multiple goals: &lt;br /&gt;
&lt;br /&gt;
1. They provide a form of documentation that shows the intent of the functionality and/or specific class/method.&lt;br /&gt;
&lt;br /&gt;
2. They provide a quick regression testing strategy that allows confidence that any future code changes do not have unexpected, adverse ramifications. &lt;br /&gt;
&lt;br /&gt;
3. A test-first approach has a general side-effect of a loosely coupled, highly cohesive, maintainable, and testable solution that greatly increases agility and significantly decreases bugs. &lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Consistency and Unity&lt;/strong&gt; &lt;br /&gt;
&lt;br /&gt;
The code should be consistent and unified. It should appear as though a single mind developed each bounded context. This can be accomplished by following various coding standards. It is important to point out that this relates to each bounded context and not the project as a whole. For example, any UI development should have a unified and consistent coding style. Likewise, any service/domain development should have a unified and consistent coding style (even if this style differs slightly from the UI development coding style). Conventions that promote consistency pertain to the standardization of layering, naming conventions, and consistent use of idioms. One great way to help ensure that these agreed upon standards are followed is to utilize a tool such as FxCop during development. &lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Versioning and Service Contract Management&lt;/strong&gt; &lt;br /&gt;
&lt;br /&gt;
In order for a system to be extensible, while continuing to support existing customers and functionality, a service contract versioning strategy must be followed. It is critical that unaffected consumers of the exposed services are not required to update/deploy changes to their systems every time that a modification/addition is implemented. This means that existing service contracts should only be modified when a non-breaking change is implemented (such as the addition of a new operation). It also implies that changes at the domain level should not automatically be propagated to the service layer (note: One strategy to prevent this issue is through the use of the DTO pattern). In the event of a required breaking-change, the service contract should be versioned using an agreed upon versioning strategy, while keeping everything as agnostic, reusable, and maintainable as possible. &lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Composability&lt;/strong&gt; &lt;br /&gt;
&lt;br /&gt;
The functionality exposed in the solution should be composable and expressive of agnostic logic. This means that the web services should be built as general services, which allow current business requirements to be met while allowing reusability for future consumers and/or business needs. This indicates that web services should rarely, if ever, be designed to support only a single client, consumer, or application. &lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Atomicity&lt;/strong&gt; &lt;br /&gt;
&lt;br /&gt;
The solution’s web services and functionality should be atomic. This means that all activity that occurs during the lifecycle of a service operation should be rolled back in the event of a failure. This ensures that the outcome of the operation is consistent with either a cancellation in conjunction with an error or a successful outcome with the expected response. &lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Fine-Granularity versus Course-Granularity&lt;/strong&gt; &lt;br /&gt;
&lt;br /&gt;
The solution should implement course-grained web services that act as a thin wrapper around a fine-grained domain model. The high level of abstraction provided by the web service interfaces allow consumers to depend on the exposed contract and receive maximum performance benefits associated with the course-grained services. The fine-grained domain model allows the solution to change whenever the business requires by providing maximum flexibility, while limiting chage to the interface(s) on which the consumers depend. &lt;br /&gt;
&lt;br /&gt;
&lt;strong&gt;Logging and Error Handling&lt;/strong&gt; &lt;br /&gt;
&lt;br /&gt;
A logging strategy should be consistently utilized throughout the development of the overall solution. At a minimum, this strategy should include the logging of any user initiated action. Additionally, the ideal strategy should including logging at a method/function level indicating entry and exit of each specific method/function. An ideal approach to accomplishing this functionality, while still adhering to the DRY principle, is to utilize an Aspect Oriented Programming (AOP) approach (Note: A great example of a framework to help with this approach for C# development is PostSharp.) Finally, the verbosity of the logged information must be configurable during run-time. A collection of possible error codes and associated descriptions should be documented and made available for delivery to consumers. In addition, all errors should be logged in a persistent and searchable data store. &lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-7978317625484843437?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/7978317625484843437/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=7978317625484843437" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/7978317625484843437?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/7978317625484843437?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/KP4NHQJRxWM/development-principles-and-standards.html" title="Development Principles and Standards" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2009/10/development-principles-and-standards.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEQESHw-fCp7ImA9WxNSF08.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-1617973494505168314</id><published>2009-08-30T20:59:00.000-07:00</published><updated>2009-08-31T06:45:09.254-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-08-31T06:45:09.254-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="F#" /><category scheme="http://www.blogger.com/atom/ns#" term="Asynchronous Workflows" /><title>F# - Asynchronous Directory.GetFiles and File.Copy</title><content type="html">&lt;b&gt;The Problem:&lt;/b&gt;&lt;br/&gt;
My wife recently decided to take on the task of ordering family photo albums.  This primarily involved wading through the deluge of digital photos that have been piling up over the last three years, selecting the photos that were worthy to be placed in the album, uploading those photos to a certain web site, organizing the photos in the albums, and finally making the purchase.  The particular imaging software, that was used to import/organize/modify the photos, stores the images in a directory structure that looks something like this ..\&amp;lt;Main Directory&amp;gt;\&amp;lt;Year&amp;gt;\&amp;lt;Month&amp;gt;\&amp;lt;Day&amp;gt;.  While this would not normally be an issue, it made the task of uploading the images to the photo album creation site quite arduous.  
&lt;br/&gt;&lt;br/&gt;
This of course is a simple problem to solve in most programming languages.  The following examples show how it could be solved with F# both synchronously and asynchronously.  While this is definitely not production ready, it provides a few samples of how asynchronous workflows can be used in the wild. 
&lt;br/&gt;&lt;br/&gt;
&lt;b&gt;The Synchronous Way:&lt;/b&gt;&lt;br/&gt;
(Note: A sleep statement has been added to emphasize the speed difference between the synchronous/asynchronous approaches.)
&lt;pre class="f-sharp" name="code"&gt;
open System.IO
let destinationDirectory = @"C:\temp\picDest\"
let sourceDirectoryRoot = @"C:\temp\pic"
let searchPattern = @"*.jpg";
let getFileName sourceFile = FileInfo(sourceFile).Name
let getSourceImages = Directory.GetFiles(sourceDirectoryRoot, searchPattern, 
                          SearchOption.AllDirectories)
let getDestinationFileName sourceFile destinationDirectory = 
    destinationDirectory + getFileName sourceFile
let copyImage sourceFile destinationDirectory = 
    File.Copy(sourceFile, getDestinationFileName sourceFile destinationDirectory, true) 
    |&amp;gt; ignore  

do printfn 
    "Starting the image consolidation process with base directory: %s" sourceDirectoryRoot
for image in getSourceImages do
    System.Threading.Thread.Sleep(5000)
    do printfn "[.NET Thread %d] %s" System.Threading.Thread.CurrentThread.ManagedThreadId image
    copyImage image destinationDirectory
do printfn "The images have been consolidated into directory %s." destinationDirectory
do printfn "Press [Enter] close this command prompt." 
System.Console.ReadKey() |&amp;gt; ignore
&lt;/pre&gt;
&lt;b&gt;The Asynchronous Way:&lt;/b&gt;&lt;br/&gt;
(Note: A sleep statement has been added to emphasize the speed difference between the synchronous/asynchronous approaches.)
&lt;pre class="f-sharp" name="code"&gt;
open System
open System.IO

type Directory with
    static member AsyncGetFiles(path:string, searchPattern:string, searchOption:SearchOption) = 
        let fn = new Func &amp;lt;string * string * SearchOption, string[]&amp;gt;(Directory.GetFiles)    
        Async.BuildPrimitive((path, searchPattern, searchOption), fn.BeginInvoke, fn.EndInvoke)
type File with
    static member AsyncCopy(sourceFile:string, destinationFile:string, overwrite:bool) = 
        let fn = new Func&amp;lt;string * string * bool, unit&amp;gt;(File.Copy)
        Async.BuildPrimitive((sourceFile, destinationFile, overwrite), fn.BeginInvoke, fn.EndInvoke)   

let destinationDirectory = @"C:\temp\picDest\"
let sourceDirectoryRoot = @"C:\temp\pic"
let searchPattern = @"*.jpg";
let getFileName sourceFile = FileInfo(sourceFile).Name
let getSourceImages imageDirectory searchPattern searchOption = 
    async { return! Directory.AsyncGetFiles(imageDirectory, searchPattern, 
                searchOption) }
let getDestinationFileName sourceFile destinationDirectory = 
    destinationDirectory + getFileName sourceFile
let copyImage sourceFile destinationDirectory overwrite = 
    async {
        System.Threading.Thread.Sleep(5000)
        do printfn 
            "[.NET Thread %d] %s" Threading.Thread.CurrentThread.ManagedThreadId sourceFile
        return! File.AsyncCopy(sourceFile, 
            getDestinationFileName sourceFile destinationDirectory, overwrite) }

do printfn 
    "Starting the image consolidation process with base directory: %s" 
    sourceDirectoryRoot

let sourceImages = 
    getSourceImages sourceDirectoryRoot searchPattern SearchOption.AllDirectories
    |&amp;gt; Async.RunSynchronously

for image in sourceImages do
    copyImage image destinationDirectory true
    |&amp;gt; Async.Start
       
do printfn 
    "The images will be consolidated into the following directory: %s" destinationDirectory 
System.Console.ReadKey() |&amp;gt; ignore
&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-1617973494505168314?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/1617973494505168314/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=1617973494505168314" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/1617973494505168314?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/1617973494505168314?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/yqjK8LKWzlI/f-asynchronous-directorygetfiles-and.html" title="F# - Asynchronous Directory.GetFiles and File.Copy" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2009/08/f-asynchronous-directorygetfiles-and.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0IFRnk5fip7ImA9WxJVEEs.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-387685238971145174</id><published>2009-06-26T19:23:00.000-07:00</published><updated>2009-06-26T19:25:17.726-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-06-26T19:25:17.726-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="CodeStock 2009" /><category scheme="http://www.blogger.com/atom/ns#" term="F#" /><title>CodeStock 2009 - The C# Developer's Guide to F#</title><content type="html">Thanks to all who came out to my session today at &lt;a href="http://www.codestock.org/"&gt;CodeStock 2009&lt;/a&gt;.  The slide deck and code samples are provided below:&lt;br /&gt;&lt;br /&gt;- &lt;a href="http://sites.google.com/site/danodocs/Home/TheCDevelopersGuidetoF.ppt?attredirects=0"&gt;Slide Deck&lt;/a&gt;&lt;br /&gt;- &lt;a href="http://sites.google.com/site/danodocs/Home/FSharpSample_CodeStock2009.zip?attredirects=0"&gt;F# Survey Provider Sample &lt;/a&gt;&lt;br /&gt;- &lt;a href="http://sites.google.com/site/danodocs/Home/FSharp_Scripts.zip?attredirects=0"&gt;F# Script Samples&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-387685238971145174?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/387685238971145174/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=387685238971145174" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/387685238971145174?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/387685238971145174?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/y74w0GB9SVc/codestock-2009-c-developers-guide-to-f.html" title="CodeStock 2009 - The C# Developer's Guide to F#" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2009/06/codestock-2009-c-developers-guide-to-f.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CEUCRXk6eip7ImA9WxJRFkw.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-6253593413733983053</id><published>2009-05-17T19:02:00.000-07:00</published><updated>2009-05-17T19:04:24.712-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-05-17T19:04:24.712-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="CodeStock 2009" /><category scheme="http://www.blogger.com/atom/ns#" term="F#" /><title>CodeStock 2009 Session: The C# Developers Guide to F#</title><content type="html">The CodeStock 2009 speakers/sessions were announced today and I am honored to say that I will be providing a session entitled "The C# Developers Guide to F#".&amp;nbsp; Thanks to all who voted for this session and I can't wait to see you all there!&lt;br /&gt;&lt;br /&gt;&lt;a href="http://codestock.org"&gt;&lt;img alt="Join me at CodeStock" height="150" width="140" src="http://codestock.org/Marketing/blog_badge.png" border="0" /&gt;&lt;/a&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-6253593413733983053?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/6253593413733983053/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=6253593413733983053" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/6253593413733983053?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/6253593413733983053?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/2w4zHPC_vok/codestock-2009-session-c-developers.html" title="CodeStock 2009 Session: The C# Developers Guide to F#" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2009/05/codestock-2009-session-c-developers.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A08HQn86fCp7ImA9WxVUGU4.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-1362631613479562483</id><published>2009-03-24T17:10:00.000-07:00</published><updated>2009-03-24T17:10:33.114-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-03-24T17:10:33.114-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Developer Events" /><title>Upcoming Developer Events/Conferences</title><content type="html">There are several upcoming developer events/conferences of which I want to make sure that everyone is aware.&lt;br /&gt;
&lt;br /&gt;
April 11 (tentative) - F# Fire Starter - Nashville, TN&lt;br /&gt;
&lt;br /&gt;
This is going to be a great event full of presentations, demonstrations, pair programming, and open spaces.&amp;nbsp; It's open to all levels of developers with all levels of F# experience.&amp;nbsp; I'll be providing more information&amp;nbsp;as it becomes available.&lt;br /&gt;
&lt;br /&gt;
June 26-27 - &lt;a href="http://codestock.org/"&gt;CodeStock 2009&lt;/a&gt; - Knoxvillle, TN&lt;br /&gt;
&lt;br /&gt;
This is a great event where&amp;nbsp;Open Spaces are mixed with&amp;nbsp;a traditional conference.&amp;nbsp; The cost is just $25 and registration will open on or after March 31st.&lt;br /&gt;
&lt;br /&gt;
August 13-15 - &lt;a href="http://www.devlink.net/"&gt;devLink 2009&lt;/a&gt;&amp;nbsp;- Nashville, TN&lt;br /&gt;
&lt;br /&gt;
DevLink features over 75&amp;nbsp;sessions of technical content intended to make you more knowledgeable and marketable.&amp;nbsp; Registration opens April 1st and the early bird cost is $75.&amp;nbsp; Note: This conference sells out every year, so get your ticket early!&lt;br /&gt;
&lt;br /&gt;
&amp;nbsp;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-1362631613479562483?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/1362631613479562483/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=1362631613479562483" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/1362631613479562483?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/1362631613479562483?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/waEbhccvc90/upcoming-developer-eventsconferences.html" title="Upcoming Developer Events/Conferences" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2009/03/upcoming-developer-eventsconferences.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0YFRn0yeSp7ImA9WxVUFUg.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-4717268865649522793</id><published>2009-03-20T06:13:00.000-07:00</published><updated>2009-03-20T06:18:37.391-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-03-20T06:18:37.391-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Nashville .NET User Group" /><category scheme="http://www.blogger.com/atom/ns#" term="F#" /><category scheme="http://www.blogger.com/atom/ns#" term="F# Presentation" /><category scheme="http://www.blogger.com/atom/ns#" term="F# Sample Application" /><title>Presentation: An Introduction to F# - Slides and Sample Code</title><content type="html">Thanks to all who came out to the Nashville .NET User Group last night.  As promised, here are the slides and examples.&lt;br /&gt;&lt;br /&gt;Click &lt;a href="http://sites.google.com/site/danodocs/Home/IntroductiontoF.zip"&gt;here&lt;/a&gt; for a zipped file containing the slides and sample script.&lt;br /&gt;&lt;br /&gt;Click &lt;a href="http://sites.google.com/site/danodocs/Home/FSharpSample.zip"&gt;here&lt;/a&gt; for a zipped file containing the source code of the sample application.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-4717268865649522793?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/4717268865649522793/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=4717268865649522793" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/4717268865649522793?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/4717268865649522793?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/oZmJLqnO92M/presentation-introduction-to-f-slides.html" title="Presentation: An Introduction to F# - Slides and Sample Code" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2009/03/presentation-introduction-to-f-slides.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkEEQXc4eyp7ImA9WxVUE0k.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-4325637564217895366</id><published>2009-03-17T19:50:00.000-07:00</published><updated>2009-03-17T19:50:00.933-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-03-17T19:50:00.933-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Nashville .NET User Group" /><category scheme="http://www.blogger.com/atom/ns#" term="F#" /><category scheme="http://www.blogger.com/atom/ns#" term="F# Sample Application" /><title>Sample F# Application - A Simple Quiz Provider</title><content type="html">One of the things that we will be discussing at the &lt;a href="http://www.nashdotnet.org/"&gt;Nashville .NET User Group&lt;/a&gt; Tomorrow night, March 19, 2009, is a sample application that has a service layer built in F#.&amp;nbsp; To access the sample code click &lt;a href="http://sites.google.com/site/danodocs/Home/FSharpSample.zip"&gt;here.&lt;/a&gt;&lt;br /&gt;
&lt;br /&gt;
A few notes:&lt;br /&gt;
&lt;br /&gt;
- The code is broken out into two main layers: Service and Presentation.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
- The service layer is built in F# and the presentation layer is build in C# with ASP.NET MVC RC1.&lt;br /&gt;
&lt;br /&gt;
- The tests are written in C# (even in the service layer) to provide examples of language interoperability.&lt;br /&gt;
&lt;br /&gt;
- To keep things as simple as possible, the data is stored in an XML file rather than a database.&amp;nbsp; All interaction with the data is through Linq to XML.&lt;br /&gt;
&lt;br /&gt;
- The intent of this example is to help existing object-oriented developers ease into the language.&amp;nbsp; Because of this, many functional programming approaches are not utilized to the full extent. &lt;br /&gt;
&lt;br /&gt;
- This uses the F# Sept. 2008 CTP.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-4325637564217895366?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/4325637564217895366/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=4325637564217895366" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/4325637564217895366?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/4325637564217895366?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/nF93KgM6Z5A/sample-f-application-simple-quiz.html" title="Sample F# Application - A Simple Quiz Provider" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2009/03/sample-f-application-simple-quiz.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DkUESX4yfSp7ImA9WxVUEkg.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-6837955401347422818</id><published>2009-03-16T18:43:00.000-07:00</published><updated>2009-03-16T18:43:28.095-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-03-16T18:43:28.095-07:00</app:edited><title>F# Presentation at the Nashville .NET User Group</title><content type="html">I will be providing a presentation at the &lt;a href="http://www.nashdotnet.org/"&gt;Nashville .NET User Group&lt;/a&gt; this Thursday, March 19, 2009. Here's the information:&lt;br /&gt;
&lt;br /&gt;
Presentation: "An Introduction to F#"&lt;br /&gt;
&lt;br /&gt;
Abstract :&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
What is F#?&amp;nbsp; Why should you care?&amp;nbsp; What advantages can F# provide for real world developers?&lt;br /&gt;
&lt;br /&gt;
In
this presentation we will answer these questions, cover the basic
syntax of F#, and explore a sample F# line-of-business application.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-6837955401347422818?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/6837955401347422818/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=6837955401347422818" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/6837955401347422818?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/6837955401347422818?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/UuSB0f-1ulE/f-presentation-at-nashville-net-user.html" title="F# Presentation at the Nashville .NET User Group" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2009/03/f-presentation-at-nashville-net-user.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CE8MR3s7cCp7ImA9WxVRE0w.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-7158224714494636216</id><published>2009-01-18T11:56:00.000-08:00</published><updated>2009-01-18T13:08:06.508-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2009-01-18T13:08:06.508-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="REST" /><category scheme="http://www.blogger.com/atom/ns#" term="F#" /><category scheme="http://www.blogger.com/atom/ns#" term="WCF" /><title>Building a RESTful Service with WCF and F#</title><content type="html">There has been a lot of discussion recently, centered on the idea of making services RESTful.&amp;nbsp; REST (Representational State Transfer) "is a key design idiom that embraces a stateless client-server
architecture in which the web services are viewed as resources and can
be identified by their URLs." &lt;a href="http://java.sun.com/developer/technicalArticles/WebServices/restful/"&gt;(1&lt;/a&gt;)&amp;nbsp; This post will provide a simple example of creating a RESTful service with WCF and F#.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Creating the project:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The first step in building our example is to create a new F# Library project.&amp;nbsp; I chose to name this project "FSharpWCF".&amp;nbsp; The next step is to add references to System.Runtime.Serialization, System.ServiceModel, and System.ServiceModel.Web.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Building the contracts:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The code looks only slightly different than an equivalent in a language such as C#, though there are a couple of key things that should be pointed out.&amp;nbsp; First, System.ServiceModel.Web has been opened.&amp;nbsp; This is the namespace that allows us to use the WebGet attribute.&amp;nbsp; The WebGet attribute allows us to set a UriTemplate that will be used for navigation to our service.&amp;nbsp; Our UriTemplate is set to "temp/{value}", which indicates that navigating to the base URL/temp/{value} will return the result of the service.&amp;nbsp; {value} associates directly with the parameter named value in our GetData operation.&amp;nbsp; The last important thing to notice is the assignment of the name "value" to the request argument of the GetData operation (i.e. abstract GetData : value:string -&amp;gt; string).&amp;nbsp; For more information on this, see &lt;a href="http://blogs.tedneward.com/2009/01/18/Building+WCF+Services+With+F+Part+1.aspx"&gt;this post by Ted Neward&lt;/a&gt;.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="f-sharp" name="code"&gt;#light
namespace FSharpWCF

open System
open System.Runtime.Serialization
open System.ServiceModel
open System.ServiceModel.Web

[&amp;lt;ServiceContract&amp;gt;]
type IGetDataService = interface 
    [&amp;lt;WebGet(UriTemplate="temp/{value}")&amp;gt;]
    [&amp;lt;OperationContract&amp;gt;]
    abstract GetData : value:string -&amp;gt; string
end

type GetDataService() = 
    interface IGetDataService with
        member this.GetData value =
            sprintf "You entered: %s" value
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Adding an app.config file:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Since an F# library doesn't have App.config as an option when adding a new item, you will need to create the file in the project directory manually, then add it as an existing item.&amp;nbsp; The main thing to notice is the addition of the endpointBehaviors section and the association of this behaviorConfiguration to the endpoint.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="c-sharp" name="code"&gt;&amp;lt;?xml version="1.0" encoding="utf-8" ?&amp;gt;
&amp;lt;configuration&amp;gt;
  &amp;lt;system.serviceModel&amp;gt;
    &amp;lt;services&amp;gt;
      &amp;lt;service name="FSharpWCF.GetDataService" behaviorConfiguration="FSharpWCF.GetDataServiceBehavior"&amp;gt;
        &amp;lt;host&amp;gt;
          &amp;lt;baseAddresses&amp;gt;
            &amp;lt;add baseAddress = "http://localhost:8080/FSharpWCF/GetDataService/" /&amp;gt;
          &amp;lt;/baseAddresses&amp;gt;
        &amp;lt;/host&amp;gt;
        &amp;lt;endpoint binding="webHttpBinding" contract="FSharpWCF.IGetDataService" 
                  behaviorConfiguration="Web"&amp;gt;
          &amp;lt;identity&amp;gt;
            &amp;lt;dns value="localhost"/&amp;gt;
          &amp;lt;/identity&amp;gt;
        &amp;lt;/endpoint&amp;gt;
      &amp;lt;/service&amp;gt;
    &amp;lt;/services&amp;gt;
    &amp;lt;behaviors&amp;gt;
      &amp;lt;serviceBehaviors&amp;gt;
        &amp;lt;behavior name="FSharpWCF.GetDataServiceBehavior"&amp;gt;
          &amp;lt;serviceMetadata httpGetEnabled="True"/&amp;gt;
          &amp;lt;serviceDebug includeExceptionDetailInFaults="False" /&amp;gt;
        &amp;lt;/behavior&amp;gt;
      &amp;lt;/serviceBehaviors&amp;gt;
      &amp;lt;endpointBehaviors&amp;gt;
        &amp;lt;behavior name="Web"&amp;gt;
          &amp;lt;webHttp/&amp;gt;
        &amp;lt;/behavior&amp;gt;
      &amp;lt;/endpointBehaviors&amp;gt;
    &amp;lt;/behaviors&amp;gt;
  &amp;lt;/system.serviceModel&amp;gt;
&amp;lt;/configuration&amp;gt;
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Testing the service:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
To test your new service, do the following:&lt;br /&gt;
&lt;br /&gt;
1. Right click on the FSharpWCF project and select properties.&lt;br /&gt;
2. Navigate to the Debug tab, change the start action to "Start external program:" and locate the WcfSvcHost.exe on your development machine (i.e. C:\Program Files\Microsoft Visual Studio 9.0\Common7\IDE\WcfSvcHost.exe).&lt;br /&gt;
3. Add the following "command line arguments:" /service:FSharpWCF.dll /config:FSharpWCF.dll.config&lt;br /&gt;
4. Set "Working directory:" to the directory of these DLLs.&lt;br /&gt;
&lt;br /&gt;
You should now be able to launch the service by running the project from Visual Studio.&amp;nbsp; This will host your service with WcfSvcHost and allow you to access your service from a browser.&amp;nbsp; (Note: WcfSvcHost should only be used for testing purposes.&amp;nbsp; You should never use this as a production host.)&lt;br /&gt;
&lt;br /&gt;
To use the service, open a browser and navigate to http://localhost:8080/FSharpWCF/GetDataService/temp/2 and you should receive &amp;lt;string&amp;gt;You entered: 2&amp;lt;/string&amp;gt; as a result.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Conclusion:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
That's all there is to it.&amp;nbsp; The service can now be viewed as a resource that can be identified by it's URL.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
Resources:&lt;br /&gt;
&lt;br /&gt;
1. http://java.sun.com/developer/technicalArticles/WebServices/restful/&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-7158224714494636216?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/7158224714494636216/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=7158224714494636216" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/7158224714494636216?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/7158224714494636216?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/2U4j3XzhsnA/building-restful-services-with-wcf-and.html" title="Building a RESTful Service with WCF and F#" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2009/01/building-restful-services-with-wcf-and.html</feedburner:origLink></entry><entry gd:etag="W/&quot;AkUNSHg_fip7ImA9WxRaGE4.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-5173547378602902529</id><published>2008-12-20T14:17:00.000-08:00</published><updated>2008-12-20T21:44:59.646-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-12-20T21:44:59.646-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="BDD" /><category scheme="http://www.blogger.com/atom/ns#" term="Rhino Mocks" /><category scheme="http://www.blogger.com/atom/ns#" term="F#" /><category scheme="http://www.blogger.com/atom/ns#" term="NUnit" /><category scheme="http://www.blogger.com/atom/ns#" term="SpecUnit" /><title>Object Mocking in F# with Rhino Mocks</title><content type="html">Near the end of Oct. 2008,&amp;nbsp;I posted an entry&amp;nbsp;entitled&amp;nbsp;&lt;a href="http://bloggemdano.blogspot.com/2008/10/mocking-f.html"&gt;Mocking F#&lt;/a&gt;.&amp;nbsp; While that post may be helpful to some, others may be looking for an example of how to dynamically mock objects from tests written in F#.&amp;nbsp; This post will attempt to provide that example.&amp;nbsp; In addition, it will provide another example&amp;nbsp;of a BDD approach using some of the functionality in SpecUnit (a previous example is &lt;a href="http://bloggemdano.blogspot.com/2008/12/behavior-driven-development-bdd-in-f.html"&gt;here&lt;/a&gt;).&lt;br /&gt;
&lt;br /&gt;
Since the types being tested have not changed from those provided in the &lt;a href="http://bloggemdano.blogspot.com/2008/10/mocking-f.html"&gt;Mocking F#&lt;/a&gt; post, I will not be re-posting them here.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="f-sharp" name="code"&gt;#light
namespace FSharpMockExample.Services.Specs
open FSharpMockExample.Services
open FSharpMockExample.Entities
open FSharpMockExample.Data
open NUnit.Framework
open SpecUnit
open Rhino.Mocks

[&amp;lt;TestFixture&amp;gt;]
[&amp;lt;Concern("Customer Balance Calculation")&amp;gt;]
type behaves_like_context_with_customer_balance_calculation() = 
    inherit ContextSpecification()
    [&amp;lt;DefaultValue(false)&amp;gt;]
    val mutable customerService : ICustomerService
    [&amp;lt;DefaultValue(false)&amp;gt;]
    val mutable mocks : MockRepository
    override this.Context () = 
        this.mocks &amp;lt;- new MockRepository()
        ignore None

[&amp;lt;TestFixture&amp;gt;]
[&amp;lt;Concern("Customer Balance Calculation")&amp;gt;]
type When_calculating_balance_with_starting_balance_of_fifty_and_ten_percent_discount() = 
    inherit behaves_like_context_with_customer_balance_calculation()
    override this.Because () = 
        this.mocks &amp;lt;- new MockRepository()
        let cAgs = [||]
        let customerDao = this.mocks.DynamicMock&amp;lt;ICustomerDao&amp;gt;(cAgs)
        let customer = new Customer(1, "XYZ Company", 50.00M)
        Expect.Call(customerDao.GetById(1)).Return(customer) |&amp;gt; ignore
        this.customerService &amp;lt;- new CustomerService(customerDao) 
    [&amp;lt;Observation&amp;gt;]
    member this.should_have_a_calculated_balance_of_forty_five() = 
        this.mocks.ReplayAll();
        this.customerService.CalculateBalaceWithDiscount(1, 0.1M).ShouldEqual(45M) |&amp;gt; ignore
        this.mocks.VerifyAll();
&lt;/pre&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-5173547378602902529?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/5173547378602902529/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=5173547378602902529" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/5173547378602902529?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/5173547378602902529?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/fHXJMJQXGcI/object-mocking-in-f-with-rhino-mocks.html" title="Object Mocking in F# with Rhino Mocks" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2008/12/object-mocking-in-f-with-rhino-mocks.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0EDQnk4fCp7ImA9WxRbGU4.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-998742852982173799</id><published>2008-12-10T06:50:00.000-08:00</published><updated>2008-12-10T09:54:33.734-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-12-10T09:54:33.734-08:00</app:edited><title>Behavior Driven Development (BDD) in F# with SpecUnit .NET</title><content type="html">&lt;b&gt;BDD Overview&lt;/b&gt;: &lt;br /&gt;
&lt;br /&gt;
Behavior Driven Development (BDD)&amp;nbsp;is a&amp;nbsp;process that&amp;nbsp;evolved from&amp;nbsp;Test Driven Development (TDD).&amp;nbsp; The differences are subtle and&amp;nbsp;primarily focus on removing communication related&amp;nbsp;confusion (Dan North-the founder of BDD-provides a nice introduction &lt;a href="http://dannorth.net/introducing-bdd"&gt;here&lt;/a&gt;).&amp;nbsp; &lt;a href="http://behaviour-driven.org/"&gt;http://behaviour-driven.org/&lt;/a&gt;&amp;nbsp;describes BDD as a convergence of TDD and Domain-Driven Design (DDD) - (A good introduction to DDD can be found on &lt;a href="http://www.hanselminutes.com/default.aspx?showID=158"&gt;Hanselminutes show #140&lt;/a&gt; with Rob Conery).&amp;nbsp; One of the foundations of DDD is the concept of removing complexity by creating a common language to help bridge the gap between business and technology .&amp;nbsp; This common language is known as the ubiquitous language.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
The first thing that BDD does to help accomplish the goal of a ubiquitous language is remove the central focus on "tests".&amp;nbsp; Generally, when the word "Test" is mentioned to a business minded person, they will immediately think about a quality assurance process that is situated near the end of a project plan.&amp;nbsp; By changing the termonology from "Test" to "Specification", the focus changes to something done near the beginning of the project plan that defines and drives the development of the solution.&amp;nbsp; This small focal shift can make a big difference in how the project is driven.&lt;br /&gt;
&lt;br /&gt;
BDD also has advantages for developers.&amp;nbsp; When specifications are documented in code, that code is more likely to accomplish the business goals, be easier to understand, and be much more maintainable over the life of the solution.&amp;nbsp; In addition, the specifications written to drive the development can then be used to prove that the final product meets all of the business requirements.&lt;br /&gt;
&lt;br /&gt;
There are many additional benefits to BDD.&amp;nbsp; For additional information, check out http://behaviour-driven.org/.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;BDD in F#:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
After reading &lt;a href="http://www.lostechies.com/blogs/sean_chambers/archive/2008/12/07/starting-with-bdd-vs-starting-with-tdd.aspx"&gt;Starting with BDD vs. TDD&lt;/a&gt;, I decided to checkout &lt;a href="http://code.google.com/p/specunit-net/"&gt;SpecUnit .NET&lt;/a&gt;.&amp;nbsp; I pulled down the sample application (i.e. Banking) and did a quick and dirty port to F#.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Specification:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="f-sharp" name="code"&gt;#light
namespace BankingFSharp.Specs
open NUnit.Framework
open SpecUnit
open BankingFSharp

[&amp;lt;TestFixture&amp;gt;]
[&amp;lt;Concern("funds transfer")&amp;gt;]
type behaves_like_context_with_from_account_and_to_account() = 
    inherit ContextSpecification()
    [&amp;lt;DefaultValue(false)&amp;gt;]
    val mutable fromAccount : Account
    [&amp;lt;DefaultValue(false)&amp;gt;]
    val mutable toAccount : Account
    override this.Context () = 
        this.fromAccount &amp;lt;- new Account(1m) 
        this.toAccount &amp;lt;- new Account(1m) 
        ignore None

[&amp;lt;Concern("funds transfer")&amp;gt;]
type when_transferring_between_two_accounts() = 
    inherit behaves_like_context_with_from_account_and_to_account()
    override this.Because () = 
        this.fromAccount.Transfer(1m, this.toAccount) |&amp;gt; ignore
    [&amp;lt;Observation&amp;gt;]    
    member this.should_debit_the_from_account_by_the_amount_transferred () =  
        this.fromAccount.Balance.ShouldEqual(0m) |&amp;gt; ignore
    [&amp;lt;Observation&amp;gt;]    
    member this.should_credit_the_to_account_by_the_amount_transferred () =  
        this.toAccount.Balance.ShouldEqual(2m) |&amp;gt; ignore
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Code:&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;&amp;nbsp;&lt;/b&gt; 
&lt;br /&gt;
&lt;pre class="f-sharp" name="code"&gt;#light
namespace BankingFSharp
open System

type Account = class
  val mutable balance: decimal;
  new (balance) = {balance = balance}
  member this.Balance
      with get() = this.balance and set(v) = this.balance &amp;lt;- v
  member this.Transfer (amount,toAccount:Account) = 
      if amount &amp;gt; this.balance then
           let errorMessage = String.Format("Cannot transfer ${0}. The available balance is ${1}.", amount, this.balance)
           failwith errorMessage
      else   
          this.Balance &amp;lt;- this.balance - amount
          toAccount.Balance &amp;lt;- toAccount.Balance + amount
end
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Result:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
When NUnit was opened, it was exciting to see how much of the story was now being conveyed through the tests.  While this is not completely ubiquitous, the output (i.e. " when transferring between two accounts" "should create the to account by the account transferred") is pretty close to what one would see in a requirements document.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;div class="separator" style="clear: both; text-align: center;"&gt;
&lt;a href="http://3.bp.blogspot.com/_HK2nW1E0B3s/ST_7Na6MkHI/AAAAAAAAABk/oPfCNCEGIog/s1600-h/SpecResults.JPG" imageanchor="1" style="margin-left: 1em; margin-right: 1em;"&gt;&lt;img border="0" src="http://3.bp.blogspot.com/_HK2nW1E0B3s/ST_7Na6MkHI/AAAAAAAAABk/oPfCNCEGIog/s320/SpecResults.JPG" /&gt;&lt;/a&gt;&amp;nbsp;&lt;/div&gt;
&lt;br /&gt;
&lt;b&gt;Conclusion:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
BDD is a positive step toward closing the gap between business and technology.&amp;nbsp; Tools such as SpecUnit .NET make this process easier and it was refreshing to see out of the box support for F#.&amp;nbsp; As more developers start to see the benefits of TDD and BDD, we will see the infamous divide between business and technology finally start to close. &lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-998742852982173799?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/998742852982173799/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=998742852982173799" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/998742852982173799?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/998742852982173799?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/nSI9MrcCdiQ/behavior-driven-development-bdd-in-f.html" title="Behavior Driven Development (BDD) in F# with SpecUnit .NET" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><media:thumbnail xmlns:media="http://search.yahoo.com/mrss/" url="http://3.bp.blogspot.com/_HK2nW1E0B3s/ST_7Na6MkHI/AAAAAAAAABk/oPfCNCEGIog/s72-c/SpecResults.JPG" height="72" width="72" /><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2008/12/behavior-driven-development-bdd-in-f.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DE4NQn8-eip7ImA9WxRbFUU.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-2966361794341819161</id><published>2008-12-06T09:55:00.000-08:00</published><updated>2008-12-06T10:09:53.152-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-12-06T10:09:53.152-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="blogs" /><category scheme="http://www.blogger.com/atom/ns#" term="F#" /><category scheme="http://www.blogger.com/atom/ns#" term="feeds" /><title>Best F# Blogs and Feeds</title><content type="html">Here is list of some of the best blogs and feeds that often contain F# related content.&lt;br /&gt;&lt;br /&gt;- &lt;a href="http://blogs.msdn.com/dsyme/"&gt;http://blogs.msdn.com/dsyme/&lt;/a&gt;&lt;br /&gt;- &lt;a href="http://tomasp.net/blog/"&gt;http://tomasp.net/blog/&lt;/a&gt;&lt;br /&gt;- &lt;a href="http://strangelights.com/blog/"&gt;http://strangelights.com/blog/&lt;/a&gt;&lt;br /&gt;- &lt;a href="http://weblogs.asp.net/podwysocki/default.aspx"&gt;http://weblogs.asp.net/podwysocki/default.aspx&lt;/a&gt;&lt;br /&gt;- &lt;a href="http://feeds.feedburner.com/planet_fsharp"&gt;http://feeds.feedburner.com/planet_fsharp&lt;/a&gt;&lt;br /&gt;- &lt;a href="http://lorgonblog.spaces.live.com/blog/"&gt;http://lorgonblog.spaces.live.com/blog/&lt;/a&gt;&lt;br /&gt;- &lt;a href="http://blogs.msdn.com/lukeh/"&gt;http://blogs.msdn.com/lukeh/&lt;/a&gt;&lt;br /&gt;- &lt;a href="http://fsharpnews.blogspot.com/"&gt;http://fsharpnews.blogspot.com/&lt;/a&gt;&lt;br /&gt;-&lt;a href="http://blogs.msdn.com/chrsmith/"&gt; http://blogs.msdn.com/chrsmith/&lt;/a&gt;&lt;br /&gt;- &lt;a href="http://www.atrevido.net/blog/"&gt;http://www.atrevido.net/blog/&lt;/a&gt;&lt;br /&gt;- &lt;a href="http://blogs.msdn.com/andrewkennedy/"&gt;http://blogs.msdn.com/andrewkennedy/&lt;/a&gt;&lt;br /&gt;-&lt;a href="http://blogs.tedneward.com/"&gt; http://blogs.tedneward.com/&lt;/a&gt;&lt;br /&gt;- &lt;a href="http://www.pandamonial.com/"&gt;http://www.pandamonial.com/&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;If you have other favorites, please post a comment with a link.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-2966361794341819161?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/2966361794341819161/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=2966361794341819161" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/2966361794341819161?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/2966361794341819161?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/ZPVnAssH8FA/best-f-blogs-and-feeds.html" title="Best F# Blogs and Feeds" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2008/12/best-f-blogs-and-feeds.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUIMQXk8eCp7ImA9WxRUGUQ.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-3424857920548060477</id><published>2008-11-29T11:38:00.000-08:00</published><updated>2008-11-29T13:19:40.770-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-11-29T13:19:40.770-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="F#" /><category scheme="http://www.blogger.com/atom/ns#" term="Unit Test" /><category scheme="http://www.blogger.com/atom/ns#" term="ILASM" /><category scheme="http://www.blogger.com/atom/ns#" term="MSTest" /><category scheme="http://www.blogger.com/atom/ns#" term="MSIL" /><category scheme="http://www.blogger.com/atom/ns#" term="ILDASM" /><title>Using MSTest With F#</title><content type="html">Before creating this blog entry, I had always written tests against my F# projects in C#.&amp;nbsp; I prefer this approach because it helps ensure optimal interoperability between the F# libraries and other .NET languages.&amp;nbsp; However, it was always assumed that the tests could just as easily have been written in F#.&amp;nbsp; While this assumption is accurate for some of the available unit testing frameworks, it is not correct for the MSTest framework.&lt;br /&gt;
&lt;br /&gt;
This post will focus on my attempt to identify a convenient method of creating F# test fixtures using the MSTest unit testing framework.&amp;nbsp; The following links provide examples using other unit testing frameworks (&lt;a href="http://sector0.dk/?p=33"&gt;NUnit&lt;/a&gt;, &lt;a href="http://weblogs.asp.net/podwysocki/archive/2008/09/12/object-oriented-f-more-extension-everything.aspx"&gt;FsTest&amp;nbsp; library for xUnit&lt;/a&gt;).&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Creating My First F# MSTest Test Fixture:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
To create the MSTest test fixture, a new F# library project was created and a reference was added to Microsoft.VisualStudio.QualityTools.UnitTestFramework.&amp;nbsp; Figure 1 shows the very simple MSTest test fixture.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Figure 1&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="f-sharp" name="code"&gt;#light
namespace FSharpTests
open Microsoft.VisualStudio.TestTools.UnitTesting

[&amp;lt;TestClass&amp;gt;]
type FSharpTestsInFSharp = class
    [&amp;lt;testmethod&amp;gt;]
    member this.FSharpTests_CanGetCustomerByIdFromDB =
       Assert.IsTrue(1=1)
end 
&lt;/pre&gt;
&lt;br /&gt;
This code compiled without issue and all seemed well until Ctrl+R,A was used to run all of the tests in the solution.&amp;nbsp; The Test Results screen appeared and all of the C# TestFixtures were represented (the new F# project was added to an existing solution, which contained a C# test project); however, my new fixture was no where to be seen.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Off to the Command Line:&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
This was very puzzling, so I decided to dig a little deeper by launching the test from the command line.&amp;nbsp; Figure 2 displays the basic syntax used (note: The actual location of the test project has been replaced with &amp;lt;project location&amp;gt;).&amp;nbsp; This test resulted in a message stating "No tests to execute".&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Figure 2:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
MSTest.exe /testcontainer:"&amp;lt;project location=""&amp;gt;\bin\Debug\FSharpSpecifications.dll"&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Now to MSIL:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
To get a better idea of what was going on, I typed ildasm, opened FSharpSpecifications.dll, and dumped all of the IL code to an ANSI file named FSharpSpecifications.il.&amp;nbsp; After several minutes of review, it was discovered that though the TestMethodAttribute is defined in the property instance, it is not defined in the method instance.&amp;nbsp; Figure 3 displays the original IL along with the new line that allows MSTest to locate the test (note: The actual location of the test project has been replaced with &amp;lt;project location&amp;gt;).&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Figure 3&lt;/b&gt; &lt;br /&gt;
&lt;br /&gt;
&lt;pre class="f-sharp" name="code"&gt;//  Microsoft (R) .NET Framework IL Disassembler.  Version 3.5.30729.1
//  Copyright (c) Microsoft Corporation.  All rights reserved.
// Metadata version: v2.0.50727
.assembly extern /*23000001*/ mscorlib
{
  .publickeytoken = (B7 7A 5C 56 19 34 E0 89 )                         // .z\V.4..
  .ver 2:0:0:0
}
.assembly extern /*23000002*/ FSharp.Core
{
  .publickeytoken = (A1 90 89 B1 C7 4D 08 09 )                         // .....M..
  .ver 1:9:6:2
}
.assembly extern /*23000003*/ Microsoft.VisualStudio.QualityTools.UnitTestFramework
{
  .publickeytoken = (B0 3F 5F 7F 11 D5 0A 3A )                         // .?_....:
  .ver 9:0:0:0
}
.assembly /*20000001*/ FSharpSpecifications
{
  .custom /*0C000003:0A000001*/ instance void [FSharp.Core/*23000002*/]Microsoft.FSharp.Core.FSharpInterfaceDataVersionAttribute/*01000002*/::.ctor(int32,
                                                                                                                                                    int32,
                                                                                                                                                    int32) /* 0A000001 */ = ( 01 00 01 00 00 00 09 00 00 00 06 00 00 00 00 00 ) 

  // --- The following custom attribute is added automatically, do not uncomment -------
  //  .custom /*0C000004:0A000002*/ instance void [mscorlib/*23000001*/]System.Diagnostics.DebuggableAttribute/*01000003*/::.ctor(valuetype [mscorlib/*23000001*/]System.Diagnostics.DebuggableAttribute/*01000003*//DebuggingModes/*01000004*/) /* 0A000002 */ = ( 01 00 01 01 00 00 00 00 ) 

  .hash algorithm 0x00008004
  .ver 0:0:0:0
}
.mresource /*28000001*/ public FSharpSignatureData.FSharpSpecifications
{
  // Offset: 0x00000000 Length: 0x000003E2
  // WARNING: managed resource file FSharpSignatureData.FSharpSpecifications created
}
.mresource /*28000002*/ public FSharpOptimizationData.FSharpSpecifications
{
  // Offset: 0x000003E8 Length: 0x000000CE
  // WARNING: managed resource file FSharpOptimizationData.FSharpSpecifications created
}
.module 'F#-Module-FSharpSpecifications'
// MVID: {492AF409-0E8B-9CF0-A745-038309F42A49}
.imagebase 0x00400000
.file alignment 0x00000200
.stackreserve 0x00100000
.subsystem 0x0003       // WINDOWS_CUI
.corflags 0x00000001    //  ILONLY
// Image base: 0x01140000

// =============== CLASS MEMBERS DECLARATION ===================

.class /*02000002*/ public auto ansi serializable beforefieldinit FSharpTests.FSharpTestsInFSharp
       extends [mscorlib/*23000001*/]System.Object/*01000001*/
{
  .custom /*0C000005:0A000006*/ instance void [Microsoft.VisualStudio.QualityTools.UnitTestFramework/*23000003*/]Microsoft.VisualStudio.TestTools.UnitTesting.TestClassAttribute/*01000008*/::.ctor() /* 0A000006 */ = ( 01 00 00 00 ) 
  .custom /*0C000006:0A000007*/ instance void [FSharp.Core/*23000002*/]Microsoft.FSharp.Core.CompilationMappingAttribute/*01000009*/::.ctor(valuetype [FSharp.Core/*23000002*/]Microsoft.FSharp.Core.SourceConstructFlags/*0100000A*/) /* 0A000007 */ = ( 01 00 03 00 00 00 00 00 ) 
  .method /*06000001*/ public specialname rtspecialname 
          instance void  .ctor() cil managed
  // SIG: 20 00 01
  {
    // Method begins at RVA 0x2050
    // Code size       10 (0xa)
    .maxstack  3
    .language '{AF046CD3-D0E1-11D2-977C-00A0C9B4D50C}', '{994B45C4-E6E9-11D2-903F-00C04FA302A1}', '{5A869D0B-6611-11D3-BD2A-0000F80849BD}'
// Source File '&amp;lt;project location&amp;gt;\CustomerDaoTests.fs' 
    .line 31,31 : 13,15 '&amp;lt;project location&amp;gt;\CustomerDaoTests.fs'
//000031:     new() = {}
    IL_0000:  /* 02   |                  */ ldarg.0
    IL_0001:  /* 28   | (0A)000004       */ call       instance void [mscorlib/*23000001*/]System.Object/*01000001*/::.ctor() /* 0A000004 */
    IL_0006:  /* 02   |                  */ ldarg.0
    IL_0007:  /* 26   |                  */ pop
    IL_0008:  /* 00   |                  */ nop
    IL_0009:  /* 2A   |                  */ ret
  } // end of method FSharpTestsInFSharp::.ctor

  .method /*06000002*/ public instance void 
          get_FSharpTests_CanGetCustomerByIdFromDB() cil managed
  // SIG: 20 00 01
  {
    // Method begins at RVA 0x2068
    // Code size       13 (0xd)
    &lt;b&gt;// This is the new line&lt;/b&gt;
    &lt;b&gt;.custom /*0C000002:0A000003*/ instance void [Microsoft.VisualStudio.QualityTools.UnitTestFramework/*23000003*/]Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute/*01000006*/::.ctor() /* 0A000003 */ = ( 01 00 00 00 ) &lt;/b&gt;
    .maxstack  4
    .line 39,39 : 9,27 ''
//000032:     [&amp;lt;TestMethod&amp;gt;]
//000033:     member this.FSharpTests_CanGetCustomerByIdFromDB = 
//000034: //        let customerDao = new CustomerDao() :&amp;gt; ICustomerDao
//000035: //        let customer = customerDao.GetByIdFromDB(2)
//000036: //        Assert.IsTrue(customer.Id = int(2))
//000037: //        Assert.IsTrue(customer.Name = "AABB, Inc")
//000038: //        Assert.IsTrue(customer.Balance = 29M)
//000039:         Assert.IsTrue(1=1)
    IL_0000:  /* 00   |                  */ nop
    IL_0001:  /* 17   |                  */ ldc.i4.1
    IL_0002:  /* 17   |                  */ ldc.i4.1
    IL_0003:  /* FE01 |                  */ ceq
    IL_0005:  /* FE14 |                  */ tail.
    IL_0007:  /* 28   | (0A)000005       */ call       void [Microsoft.VisualStudio.QualityTools.UnitTestFramework/*23000003*/]Microsoft.VisualStudio.TestTools.UnitTesting.Assert/*01000007*/::IsTrue(bool) /* 0A000005 */
    IL_000c:  /* 2A   |                  */ ret
  } // end of method FSharpTestsInFSharp::get_FSharpTests_CanGetCustomerByIdFromDB

  .property /*17000001*/ instance class [FSharp.Core/*23000002*/]Microsoft.FSharp.Core.Unit/*01000005*/
          FSharpTests_CanGetCustomerByIdFromDB()
  {
    .custom /*0C000002:0A000003*/ instance void [Microsoft.VisualStudio.QualityTools.UnitTestFramework/*23000003*/]Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute/*01000006*/::.ctor() /* 0A000003 */ = ( 01 00 00 00 ) 
    .get instance void FSharpTests.FSharpTestsInFSharp/*02000002*/::get_FSharpTests_CanGetCustomerByIdFromDB() /* 06000002 */
  } // end of property FSharpTestsInFSharp::FSharpTests_CanGetCustomerByIdFromDB
} // end of class FSharpTests.FSharpTestsInFSharp

.class /*02000003*/ private abstract auto ansi sealed beforefieldinit '&amp;lt;StartupCode$FSharpSpecifications&amp;gt;'.$CustomerDaoTests
       extends [mscorlib/*23000001*/]System.Object/*01000001*/
{
  .field /*04000001*/ static assembly native int _init
  .custom /*0C000001:0A000008*/ instance void [mscorlib/*23000001*/]System.Runtime.CompilerServices.CompilerGeneratedAttribute/*0100000B*/::.ctor() /* 0A000008 */ = ( 01 00 00 00 ) 
} // end of class '&amp;lt;StartupCode$FSharpSpecifications&amp;gt;'.$CustomerDaoTests

.class /*02000004*/ private abstract auto ansi sealed beforefieldinit '&amp;lt;PrivateImplementationDetails$FSharpSpecifications&amp;gt;'
       extends [mscorlib/*23000001*/]System.Object/*01000001*/
{
} // end of class '&amp;lt;PrivateImplementationDetails$FSharpSpecifications&amp;gt;'


// =============================================================

// *********** DISASSEMBLY COMPLETE ***********************

&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Running the Tests From the Altered DLL:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
With the new line added to the IL file, I created a new dll using the command specificed in Figure 4 (note: The actual location of the test project has been replaced with &amp;lt;project location&amp;gt;), then ran the test using the command specified in Figure 2.&amp;nbsp; This time the test was identified and successfully run.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Figure 4&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
ilasm "&amp;lt;project location&amp;gt;\FSharpSpecifications.il" /DLL&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Conclusion:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The point of this little experiment was to find a convenient way to implement test fixtures in F# using the MSTest unit testing framework.&amp;nbsp; Unfortunately, this goal was not reached, though a certain level of success was achieved.&amp;nbsp; It is likely that full support will be provided when F# is officially shipped with VS, but until that time we can always continue to create F# test fixtures in NUnit/xUnit or use my prefered approach and write the tests in C#.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-3424857920548060477?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/3424857920548060477/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=3424857920548060477" title="2 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/3424857920548060477?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/3424857920548060477?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/HXw_fA1Kgts/using-mstest-with-f.html" title="Using MSTest With F#" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">2</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2008/11/using-mstest-with-f.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DUYASH0-cSp7ImA9WxRUEko.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-6435940609719921497</id><published>2008-11-21T05:02:00.000-08:00</published><updated>2008-11-21T06:19:09.359-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-11-21T06:19:09.359-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="F# tools" /><category scheme="http://www.blogger.com/atom/ns#" term="F# libraries" /><title>F# Tools and Libraries</title><content type="html">Since F# is still in infancy, the number of associated tools and libraries is minimal when compared to more mature languages.  However, the list is growing and will continue to increase as more and more developers get introduced to the language.&lt;br /&gt;
&lt;br /&gt;
The following, is a list of tools and libraries compiled through various Google searches.&amp;nbsp; Since the line is sometimes blurred between a tool/library, I have generally relied upon the author's description to determine the correct category.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Tools:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://code.google.com/p/fsunit/"&gt;fsunit&lt;/a&gt; - This is a testing (a.k.a. specifications) framework written in F# for F#.&lt;br /&gt;
&lt;a href="http://webdevdotnet.blogspot.com/2008/11/new-f-syntaxhighlighter-brush.html"&gt;F# SyntaxHighlighter Brush&lt;/a&gt; - This is an add on to &lt;a href="http://code.google.com/p/syntaxhighlighter/"&gt;SyntaxHighlighter&lt;/a&gt;, which allows F# code to be posted on a web page and displayed as it would in Visual Studio.&lt;br /&gt;
&lt;a href="http://www.codeplex.com/fswebtools"&gt;FS Web Tools&lt;/a&gt; - This is a set of tools to "author homogeneous client/server/database web applications".&lt;br /&gt;
&lt;a href="http://research.microsoft.com/research/downloads/Details/6a34a558-ab57-424f-a799-f0fc458105c1/Details.aspx?0sr=d"&gt;AbsIL SDK&lt;/a&gt;&amp;nbsp; - Allows manipulation of .NET files and binaries.&lt;br /&gt;
&lt;a href="http://www.codeplex.com/fsmpitools"&gt;F# MPI Tools&lt;/a&gt; - This is a message passing interface (MPI) tool that can be used to develop distributed memory applications.&lt;br /&gt;
&lt;a href="http://fortysix-and-two.blogspot.com/2008/05/fscheck-random-testing-for-f.html"&gt;FsCheck&lt;/a&gt;&amp;nbsp; - This is "a tool for testing F# code automatically".&lt;br /&gt;
&lt;a href="http://coherentpdf.com/blog/?p=22"&gt;PDF Toolkit&lt;/a&gt;&amp;nbsp; - This is a command line tool that allows manipulation of PDF files.&lt;br /&gt;
&lt;a href="http://research.microsoft.com/fsharp/release.aspx"&gt;fsc.exe&lt;/a&gt; - This is the compiler that comes with the F# CTP.&lt;br /&gt;
&lt;a href="http://research.microsoft.com/fsharp/release.aspx"&gt;fsi.exe &lt;/a&gt;- This is the interactive tool that comes with the F# CTP.&lt;br /&gt;
&lt;a href="http://research.microsoft.com/fsharp/release.aspx"&gt;fslex.exe&lt;/a&gt; - This is a tool used to create lexical analyzers that comes with the F# CTP.&lt;br /&gt;
&lt;a href="http://research.microsoft.com/fsharp/release.aspx"&gt;fsyacc.exe &lt;/a&gt;- This is a tool used to create parsers that comes with the F# CTP.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Libraries:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;a href="http://cs.hubfs.net/blogs/hell_is_other_languages/archive/2008/01/16/4565.aspx"&gt;STM for F#&lt;/a&gt; - This is a software transactional memory (STM) library for F#.&lt;br /&gt;
&lt;a href="http://www.quanttec.com/fparsec/"&gt;FParsec&lt;/a&gt;&amp;nbsp; - This is an F# parser combinator library ported from Haskell.&lt;br /&gt;
&lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyId=348F73FD-593D-4B3C-B055-694C50D2B0F3&amp;amp;displaylang=en"&gt;Parallel Extensions Library&lt;/a&gt; - This library is not specific to F#, but lends itself nicely to the "immutable by default" approach.&amp;nbsp; It provides "a &lt;span&gt;managed programming model for data parallelism, task parallelism,
and coordination on parallel hardware unified by a common work scheduler".&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span&gt;&lt;b&gt;Conclusion:&lt;/b&gt; &lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;span&gt;One of the major advantages that F# has over other functional programming languages is the .NET framework.&amp;nbsp; This allows almost any .NET tool/library to be compatible with F#.&amp;nbsp; In addition, a number of tools/libraries have been created specifically with F# in mind and that number will continue to increase.&amp;nbsp; Feel free to leave a comment linking to those that I have missed.&lt;br /&gt;&lt;/span&gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-6435940609719921497?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/6435940609719921497/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=6435940609719921497" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/6435940609719921497?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/6435940609719921497?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/4NqtonBCac8/f-tools-and-libraries.html" title="F# Tools and Libraries" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2008/11/f-tools-and-libraries.html</feedburner:origLink></entry><entry gd:etag="W/&quot;DEQCSXc5fSp7ImA9WxRVF0U.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-6428630850414090712</id><published>2008-11-15T11:31:00.000-08:00</published><updated>2008-11-15T13:59:28.925-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-11-15T13:59:28.925-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="F#" /><category scheme="http://www.blogger.com/atom/ns#" term="Ling to SQL" /><category scheme="http://www.blogger.com/atom/ns#" term="FLinq" /><title>Linq to SQL in F#</title><content type="html">In the entry titled &lt;a href="http://bloggemdano.blogspot.com/2008/11/linq-to-xml-in-f.html"&gt;Linq to XML in F#&lt;/a&gt;, I walked through an example of how to use Linq to XML in F# to retrieve customer information from an XML file.  In this post, I will show how this same functionality can be achieved with a database using the "experimental" Linq to SQL (a.k.a. FLinq) support found in  FSharp.Powerpack.FLinq.dll that was released in the &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=61ad6924-93ad-48dc-8c67-60f7e7803d3c&amp;amp;displaylang=en"&gt;Sept. 2008 CTP&lt;/a&gt;.  Don Syme states that this "is labelled experimental because some advanced SQL concepts are not yet handled (e.g. left-outer-joins)" (&lt;a href="http://cs.hubfs.net/forums/thread/6905.aspx"&gt;post by Don&lt;/a&gt; - Note: This post also contains several FLinq examples).&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Path to Completion:&lt;/b&gt;&lt;br /&gt;
Since basic Separation of Concern (SoC) concepts were originally applied, only the data access layer will need to be updated to support the change from an XML repository to a SQL repository. &lt;br /&gt;
&lt;br /&gt;
The following steps will need to be completed to accomplish this goal:&lt;br /&gt;
1. Create the test.&lt;br /&gt;
2. Create the database.&lt;br /&gt;
3. Generate the object model.&lt;br /&gt;
4. Implement the functionality.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Creating the Test:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
This test is going to be similar to that which was written for the Linq to XML example.  It will simply retrieve a customer object based on a specified Customer id.  For example purposes only, I will be adding these methods/functions into the same projects that were created in the Linq to XML example.&lt;br /&gt;
&lt;pre class="c-sharp" name="code"&gt;        
[TestMethod]
public void CanGetCustomerByIdFromDB()
{   
    FSharpMockExample.Data.ICustomerDao customerDao = new FSharpMockExample.Data.CustomerDao();   
    FSharpMockExample.Entities.ICustomer customer = customerDao.GetByIdFromDB(2);      
    Assert.AreEqual(customer.Id, 2);   
    Assert.AreEqual(customer.Name, "AABB, Inc");        
    Assert.AreEqual(customer.Balance, 30);
} 
&lt;/pre&gt;
&lt;b&gt;Creating the Database:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The database for this example is very simple with a single table that contains three fields.&lt;br /&gt;
&lt;br /&gt;
Here are the steps that were followed to create the database using the SQL Server 2005 Express Edition:&lt;br /&gt;
&lt;br /&gt;
1. Create a database called FSharpSample.&lt;br /&gt;
2. Run the following script to create the table:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="c-sharp" name="code"&gt;USE [FSharpSample]
GO
SET ANSI_NULLS ON
GO
SET QUOTED_IDENTIFIER ON
GO
SET ANSI_PADDING ON
GO
CREATE TABLE [dbo].[Customers](
    [CustomerId] [int] NOT NULL,
    [Name] [varchar](50) NOT NULL,
    [Balance] [decimal](18, 2) NOT NULL, CONSTRAINT [PK_Customers] PRIMARY KEY CLUSTERED (    [CustomerId] ASC)
WITH (PAD_INDEX  = OFF, STATISTICS_NORECOMPUTE  = OFF, IGNORE_DUP_KEY = OFF, ALLOW_ROW_LOCKS  = ON, ALLOW_PAGE_LOCKS  = ON) 
ON [PRIMARY]) ON [PRIMARY]
GO
SET ANSI_PADDING OFF 
&lt;/pre&gt;
3. Populate the table with the following script:&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="c-sharp" name="code"&gt;USE [FSharpSample]
GO
INSERT INTO dbo.Customers (CustomerId, Name, Balance)VALUES (1, 'ABC Company', 20.00)
INSERT INTO dbo.Customers (CustomerId, Name, Balance)VALUES (2, 'AABB, Inc', 30.00)
GO
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Generating the Object Model:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The object model is generated using the code generation tool called SqlMetal.exe, which is often found in c:\program files\Microsoft SDKS\Windows\v6.0A\bin\.  Since SqlMetal.exe does not yet support F#, the object model is generated in C#.&lt;br /&gt;
&lt;br /&gt;
There are a lot of ways to generate the object model; however, for this specific example I did the following:&lt;br /&gt;
&lt;br /&gt;
1. Open a command prompt and navigate to c:\program files\Microsoft SDKS\Windows\v6.0A\bin\.&lt;br /&gt;
2. Execute the following command: sqlmetal /server:".\SQLEXPRESS" /database:FSharpSample /namespace:FSharpSample /code:FSharpSampleDB.cs /language:csharp&lt;br /&gt;
3. This generates a file called FSharpSampleDB.cs and places it in the c:\program files\Microsoft SDKS\Windows\v6.0A\bin\ directory.&lt;br /&gt;
4. Create a new CSharp Class Library project within the solution and add FSharpSampleDB.cs to it.&lt;br /&gt;
5. Build the new project.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;On to the F# Code:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The first step that is needed to support FLinq in a project is to add references to System.Data, System.Data.Linq, and FSharp.PowerPack.Linq.&lt;b&gt;  &lt;/b&gt;After that, it is simply a matter of adding a new member to the CustomerDao class.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;Signature File:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The only change to the CustomerDao signature file is the addition of one new abstract member.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="f-sharp" name="code"&gt;#light
namespace FSharpMockExample.Data
open FSharpMockExample.Entities
open System.Xml.Linq

type ICustomerDao = interface
    abstract GetById: int -&amp;gt; ICustomer
    abstract GetById: XElement * int -&amp;gt; ICustomer
    abstract GetByIdFromDB: int -&amp;gt; ICustomer
end

type CustomerDao = class
    new: unit -&amp;gt; CustomerDao
    interface ICustomerDao
end
&lt;/pre&gt;
&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;br /&gt;
&lt;b&gt;Source File&lt;/b&gt;:&lt;br /&gt;
&lt;br /&gt;
The first thing that should be noticed is the #nowarn "57" compiler directive.  Since FLinq is still in the "experimental" phase, this directive is necessary to suppress the related warning.  Next, you'll notice that the Microsoft.FSharp.Linq and FSharpSampleDB namespaces have been opened. The rest of the work is in the GetByIdFromDB member.&lt;br /&gt;
&lt;br /&gt;
Here's a description of the GetByIdFromDB member:&lt;br /&gt;
&lt;br /&gt;
1. The first identifier is set to the database connection string (note: This is hard coded for example purposes only.  Normally the value would be stored in a config file.) &lt;br /&gt;
2. The second identifier is set to a new instance of the DataContext.&lt;br /&gt;
3. Finally we build and execute a Linq Query Expression. There are a few interesting things that should be noticed.  First, the quoted expression identified by "&amp;lt;@" and  "@&amp;gt;".  These quotations cause the compiler to treat the syntax within them in a special way.  Second, the Seq.hd function causes only the first element to be returned.  Finally, the resulting object is cast to the ICustomerDao interface.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="f-sharp" name="code"&gt;#light
#nowarn "57"
namespace FSharpMockExample.Data
open FSharpMockExample.Entities
open System.Xml.Linq
open Microsoft.FSharp.Linq
open FSharpSampleDB

module XLinqHelper = 
    let GetXName xname = XName.op_Implicit(xname)

type ICustomerDao = interface
    abstract GetById: int -&amp;gt; ICustomer
    abstract GetById: XElement * int -&amp;gt; ICustomer
    abstract GetByIdFromDB: int -&amp;gt; ICustomer
end

type CustomerDao = class
    new()={}
    interface ICustomerDao with
        member this.GetById id =
            let rawXml = "removed from this sample"
            let thisInterface = (this :&amp;gt; ICustomerDao)
            let xml = XElement.Parse rawXml
            thisInterface.GetById (xml, id)

        member this.GetById (xml, id) =
            let GetCustomer (customerElement:XElement) = 
                new Customer(int(customerElement.Attribute(XLinqHelper.GetXName "Id").Value), 
                    customerElement.Attribute(XLinqHelper.GetXName "Name").Value, 
                    decimal(customerElement.Attribute(XLinqHelper.GetXName "Balance").Value)) :&amp;gt; ICustomer

            xml.Elements() |&amp;gt; Seq.find(fun customer -&amp;gt; (int(customer.Attribute(XLinqHelper.GetXName "Id").Value) = id)) 
                           |&amp;gt; GetCustomer
        member this.GetByIdFromDB id =
            let connString = @"Integrated Security=SSPI;Persist Security Info=False;Initial Catalog=FSharpSample;Data Source=.\SQLEXPRESS"

            let db = new FSharpSampleDB(connString)

            Query.query &amp;lt;@ seq { for c in db.Customers do
                                 if id = c.CustomerId then
                                     yield (new Customer(c.CustomerId, c.Name, c.Balance))} 
                   |&amp;gt; Seq.hd @&amp;gt; :&amp;gt; ICustomer

end&lt;/pre&gt;
&lt;b&gt;Conclusion:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
With the help of Flinq and some basic SoC principles, switching our data access layer from an XML repository to a SQL repository is trivial.  While Flinq is not yet ready for production, full support is likely in the not too distant future.  With Flinq, the future looks bright!&lt;b&gt;&lt;br /&gt;&lt;/b&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-6428630850414090712?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/6428630850414090712/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=6428630850414090712" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/6428630850414090712?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/6428630850414090712?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/tQ2IIFY57T0/linq-to-sql-in-f.html" title="Linq to SQL in F#" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2008/11/linq-to-sql-in-f.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D08EQnk4eyp7ImA9WxRVFUU.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-4838647729774468607</id><published>2008-11-13T06:00:00.000-08:00</published><updated>2008-11-13T06:16:43.733-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-11-13T06:16:43.733-08:00</app:edited><title>Great F# Resources</title><content type="html">For those of you interested in F#, here are some great resources worth checking out.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
- &lt;a href="http://cs.hubfs.net/"&gt;HubFS&lt;/a&gt; - Here you will find forums, announcements, and many other resources.&amp;nbsp; Don Syme is often spotted here answering questions and posting examples.&lt;br /&gt;
- &lt;a href="http://blogs.msdn.com/dsyme/"&gt;Don Syme's Blog&lt;/a&gt; - This is the blog of the creator of F# and one of the authors of the book &lt;a href="http://www.amazon.com/Expert-F-Experts-Voice-Net/dp/1590598504/ref=pd_bbs_sr_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1226555595&amp;amp;sr=8-1"&gt;Expert F#&lt;/a&gt;.&lt;br /&gt;
- &lt;a href="http://www.strangelights.com/blog/"&gt;Robert Pickering's Blog&lt;/a&gt; - Author of the book &lt;a href="http://www.amazon.com/Foundations-F-Experts-Voice-Net/dp/1590597575/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1226555638&amp;amp;sr=1-1"&gt;Foundations of F#&lt;/a&gt; and recent guest on &lt;a href="http://www.hanselminutes.com/default.aspx?showID=94"&gt;Hansel Minutes show #76&lt;/a&gt;&lt;br /&gt;
- &lt;a href="http://blogs.tedneward.com/"&gt;Ted Neward's Blog&lt;/a&gt; - Ted was recently on &lt;a href="http://www.dotnetrocks.com/default.aspx?showNum=377"&gt;DNR show #377&lt;/a&gt; discussing F# with Amanda Laucher.&amp;nbsp; They are currently working on a book.&lt;br /&gt;
- &lt;a href="http://www.pandamonial.com/"&gt;Amanda Laucher's Blog&lt;/a&gt; &lt;br /&gt;
- &lt;a href="http://www.manning.com/petricek/"&gt;Real World Functional Programming&lt;/a&gt; by Tomas Petricek &lt;br /&gt;
- &lt;a href="http://msdn.microsoft.com/en-us/fsharp/default.aspx"&gt;F# MSDN Developer Center&lt;/a&gt; - This site has several great resources to get you started including links to the latest release, free chapters of Expert F#, announcements, and specification documentation.&lt;br /&gt;
- &lt;a href="http://www.codeplex.com/fsharpsamples"&gt;Examples on CodePlex&lt;/a&gt; - Contains links to additional resources including several listed on this blog entry.&lt;br /&gt;
- &lt;a href="http://codebetter.com/blogs/matthew.podwysocki/"&gt;Matthew Podwysocki's blog&lt;/a&gt; - Contains great content and examples.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
If you know of other great resources, let me know!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-4838647729774468607?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/4838647729774468607/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=4838647729774468607" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/4838647729774468607?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/4838647729774468607?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/eGZ8cEEQ7SQ/great-f-resources.html" title="Great F# Resources" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2008/11/great-f-resources.html</feedburner:origLink></entry><entry gd:etag="W/&quot;CUQBRXg4cSp7ImA9WxRVEk8.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-6078520390828004295</id><published>2008-11-08T07:12:00.000-08:00</published><updated>2008-11-09T01:35:54.639-08:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-11-09T01:35:54.639-08:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="XLinq" /><category scheme="http://www.blogger.com/atom/ns#" term="F#" /><category scheme="http://www.blogger.com/atom/ns#" term="System.Xml.Linq" /><category scheme="http://www.blogger.com/atom/ns#" term="Linq to XML" /><title>Linq to XML in F#</title><content type="html">Last week in the entry titled "&lt;a href="http://bloggemdano.blogspot.com/2008/10/mocking-f.html"&gt;Mocking F#&lt;/a&gt;", we walked through the creation of a customer service implementation in F# and explored how a dynamic mock object framework can be used to help quickly drive development with tests. In that entry, we implemented a DAO (Data Access Object) that simply creates a dummy customer class . This blog entry will focus on adding functionality to that CustomerDao class so that it retrieves the data from an XML file using Linq to XML.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;First, Add References&lt;/b&gt;:&lt;br /&gt;
&lt;br /&gt;
The first step that we must do is add a reference to System.Xml and System.Xml.Linq in both the test project and the F# project.&lt;br /&gt;
&lt;br /&gt;
&lt;b&gt;The C# Tests:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The goal of these tests is to verify that a specific customer can be retrieved from the XML source.&amp;nbsp; Method "CanGetCustomerById" retrieves the customer from the actual XML source (which in this case is hard coded into the GetById member, but could have easily been retrieved from a file or database).&amp;nbsp; Method "CanGetCustomerByIdWithXmlProvided" creates a fake XElement and passes it to the function for test purposes.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="c-sharp" name="code"&gt;        
[TestMethod]
public void CanGetCustomerById()
{
    FSharpMockExample.Data.ICustomerDao customerDao = new  FSharpMockExample.Data.CustomerDao();
    FSharpMockExample.Entities.ICustomer customer = customerDao.GetById(1);
    Assert.AreEqual(customer.Id, 1);
    Assert.AreEqual(customer.Name, "ABC Company");
    Assert.AreEqual(customer.Balance, 20);
}

[TestMethod]
public void CanGetCustomerByIdWithXmlProvided()
{
    XElement xElement =
        new XElement("c",
            new XElement("Customer",
                new XAttribute("Id", "1"),
                new XAttribute("Name", "ABC Company"),
                new XAttribute("Balance", "20.00")),
            new XElement("Customer",
                new XAttribute("Id", "2"),
                new XAttribute("Name", "AABB, Inc"),
                new XAttribute("Balance", "30.00")));
    FSharpMockExample.Data.ICustomerDao customerDao = new FSharpMockExample.Data.CustomerDao();
    FSharpMockExample.Entities.ICustomer customer = customerDao.GetById(xElement, 2);
    Assert.AreEqual(customer.Id, 2);
    Assert.AreEqual(customer.Name, "AABB, Inc");
    Assert.AreEqual(customer.Balance, 30);
}
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;The F# Signature File:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
The signature file looks very similar to that which was created during the last entry.  The main difference is a new overloaded GetById function, which contains a tuple (a tuple is common F# data structure used to group data types) of type "XElement * int".  Since XElement is used, we must also open System.Xml.Linq.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="f-sharp" name="code"&gt;#light
namespace FSharpMockExample.Data
open FSharpMockExample.Entities
open System.Xml.Linq

type ICustomerDao = interface
    abstract GetById: int -&amp;gt; ICustomer
    abstract GetById: XElement * int -&amp;gt; ICustomer
end

type CustomerDao = class
    new: unit -&amp;gt; CustomerDao
    interface ICustomerDao
end
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;The F# Source File:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
Most of the changes are found in this file.&amp;nbsp; The first thing that an astute reader might notice is the XLinqHelper module.&amp;nbsp; Modules provide a way to group and reuse identifiers and functions.&amp;nbsp; The CustomerDao class encapsulates the majority of the changes.&amp;nbsp; Member GetById xml retrieves, and in this sample actually creates, the source xml.&amp;nbsp; It then casts the current class to the ICustomerDao interface, parses the raw xml into an XElement and calls the overloaded GetById XElement*int member.&amp;nbsp; The overloaded GetById XElement*int member uses the Seq library to find the customer by the specified CustomerId, news up a customer object, casts it to an ICustomer, and finally returns the result.&lt;br /&gt;
&lt;br /&gt;
&lt;pre class="f-sharp" name="code"&gt;#light
namespace FSharpMockExample.Data
open FSharpMockExample.Entities
open System.Xml.Linq

module XLinqHelper = 
    let GetXName xname = XName.op_Implicit(xname)

type ICustomerDao = interface
    abstract GetById: int -&amp;gt; ICustomer
    abstract GetById: XElement * int -&amp;gt; ICustomer
end

type CustomerDao = class
    new()={}
    interface ICustomerDao with
        member this.GetById id =
            let rawXml = "&amp;lt;Customers&amp;gt;
                              &amp;lt;Customer Id=\"1\" Name=\"ABC Company\" Balance=\"20.00\"/&amp;gt;
                              &amp;lt;Customer Id=\"2\" Name=\"AABB, Inc\" Balance=\"30.00\"/&amp;gt;
                          &amp;lt;/Customers&amp;gt;"
            let thisInterface = (this :&amp;gt; ICustomerDao)
            let xml = XElement.Parse rawXml
            thisInterface.GetById (xml, id)

        member this.GetById (xml, id) =
            let GetCustomer (customerElement:XElement) = 
                new Customer(int(customerElement.Attribute(XLinqHelper.GetXName "Id").Value), 
                    customerElement.Attribute(XLinqHelper.GetXName "Name").Value, 
                    decimal(customerElement.Attribute(XLinqHelper.GetXName "Balance").Value)) :&amp;gt; ICustomer

            xml.Elements() |&amp;gt; Seq.find(fun customer -&amp;gt; (int(customer.Attribute(XLinqHelper.GetXName "Id").Value) = id)) 
                           |&amp;gt; GetCustomer
end
&lt;/pre&gt;
&lt;br /&gt;
&lt;b&gt;Conclusion:&lt;/b&gt;&lt;br /&gt;
&lt;br /&gt;
As you can see from the example, adding basic data access functionality using Linq to XML is pretty easy.&amp;nbsp; With the help of the Seq library and System.Xml.Linq, the possibilities of XML data manipulation are endless.&amp;nbsp; &lt;br /&gt;
&lt;br /&gt;
A special thanks goes out to &lt;a href="http://webdevdotnet.blogspot.com/"&gt;Elijah Manor&lt;/a&gt; for adding F# support to Syntax Higherlighter.&amp;nbsp; Very cool Elijah!!&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-6078520390828004295?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/6078520390828004295/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=6078520390828004295" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/6078520390828004295?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/6078520390828004295?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/s8EmfNWuWKA/linq-to-xml-in-f.html" title="Linq to XML in F#" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2008/11/linq-to-xml-in-f.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0MHRns9eCp7ImA9WxRWFEU.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-1381007471654403296</id><published>2008-10-31T13:27:00.001-07:00</published><updated>2008-10-31T13:37:17.560-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-10-31T13:37:17.560-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="F# members" /><category scheme="http://www.blogger.com/atom/ns#" term="F# interfaces" /><category scheme="http://www.blogger.com/atom/ns#" term="F# properties" /><category scheme="http://www.blogger.com/atom/ns#" term="F# classes" /><category scheme="http://www.blogger.com/atom/ns#" term="F#" /><category scheme="http://www.blogger.com/atom/ns#" term="mock objects" /><title>Mocking F#</title><content type="html">&lt;p&gt;The intent of this entry is to show how to do TDD (Test Driven Development) in F# with the help of a dynamic mock object framework such as &lt;a href="http://ayende.com/projects/rhino-mocks.aspx"&gt;RhinoMocks&lt;/a&gt;. Along the way, we will explore how to implement an object oriented design in F# with features including namespaces, classes, interfaces, properties, and members. This example includes several best practices, but is by no means production ready. Most specifically, it is missing error handling and validation. In addition, certain patterns and practices have been intentionally ignored in order to make the example a little easier to understand.&lt;/p&gt;  &lt;p&gt;This is an implementation of a simplified customer service that might exist in any standard LOB (Line of Business) application. In the end, we have a service that allows the current balance of a customer to be returned with a specified discount applied.&lt;/p&gt;  &lt;p&gt;As always, we write the tests first (Note: As is my usual style, the tests are in C# and the code is in F#):&lt;/p&gt;  &lt;p&gt;&lt;strong&gt;C# Customer Entity Test:&lt;/strong&gt;&lt;/p&gt;  &lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;TestMethod&lt;/span&gt;]&lt;br /&gt;&lt;span style="color: blue"&gt;public void &lt;/span&gt;CanCreateCustomer()&lt;br /&gt;{&lt;br /&gt;    FSharpMockExample.Entities.&lt;span style="color: #2b91af"&gt;ICustomer &lt;/span&gt;customer = &lt;span style="color: blue"&gt;new &lt;/span&gt;FSharpMockExample.Entities.&lt;span style="color: #2b91af"&gt;Customer&lt;/span&gt;(1, &lt;span style="color: #a31515"&gt;&amp;quot;ABC, Corp.&amp;quot;&lt;/span&gt;, 20);&lt;br /&gt;    &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.AreEqual(customer.Id, 1);&lt;br /&gt;    &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.AreEqual(customer.Name, &lt;span style="color: #a31515"&gt;&amp;quot;ABC, Corp.&amp;quot;&lt;/span&gt;);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;[&lt;span style="color: #2b91af"&gt;TestMethod&lt;/span&gt;]&lt;br /&gt;&lt;span style="color: blue"&gt;public void &lt;/span&gt;CanCalculateBalanceWith10PercentDiscount()&lt;br /&gt;{&lt;br /&gt;    FSharpMockExample.Entities.&lt;span style="color: #2b91af"&gt;ICustomer &lt;/span&gt;customer = &lt;span style="color: blue"&gt;new &lt;/span&gt;  FSharpMockExample.Entities.&lt;span style="color: #2b91af"&gt;Customer&lt;/span&gt;(1, &lt;span style="color: #a31515"&gt;&amp;quot;ABC, Corp.&amp;quot;&lt;/span&gt;, 20);&lt;br /&gt;    &lt;span style="color: blue"&gt;decimal &lt;/span&gt;newBalance = customer.CalculateBalanceWithDiscount(.1M);&lt;br /&gt;    &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.AreEqual(newBalance, 18);&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;F# Customer Entity:&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Signature File:&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;#light&lt;br /&gt;namespace &lt;/span&gt;FSharpMockExample.Entities&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue"&gt;type &lt;/span&gt;ICustomer = &lt;span style="color: blue"&gt;interface&lt;br /&gt;    abstract &lt;/span&gt;Id: int &lt;span style="color: blue"&gt;with &lt;/span&gt;get&lt;br /&gt;    &lt;span style="color: blue"&gt;abstract &lt;/span&gt;Name: string &lt;span style="color: blue"&gt;with &lt;/span&gt;get&lt;br /&gt;    &lt;span style="color: blue"&gt;abstract &lt;/span&gt;CalculateBalanceWithDiscount: decimal &lt;span style="color: blue"&gt;-&amp;gt; &lt;/span&gt;decimal&lt;br /&gt;&lt;span style="color: blue"&gt;end&lt;br /&gt;&lt;br /&gt;type &lt;/span&gt;Customer = &lt;span style="color: blue"&gt;class&lt;br /&gt;    new&lt;/span&gt;: int*string*decimal &lt;span style="color: blue"&gt;-&amp;gt; &lt;/span&gt;Customer&lt;br /&gt;    &lt;span style="color: blue"&gt;interface &lt;/span&gt;ICustomer &lt;br /&gt;&lt;span style="color: blue"&gt;end&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Source File:&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;#light&lt;br /&gt;namespace &lt;/span&gt;FSharpMockExample.Entities&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue"&gt;type &lt;/span&gt;ICustomer = &lt;span style="color: blue"&gt;interface&lt;br /&gt;    abstract &lt;/span&gt;Id: int &lt;span style="color: blue"&gt;with &lt;/span&gt;get&lt;br /&gt;    &lt;span style="color: blue"&gt;abstract &lt;/span&gt;Name: string &lt;span style="color: blue"&gt;with &lt;/span&gt;get&lt;br /&gt;    &lt;span style="color: blue"&gt;abstract &lt;/span&gt;CalculateBalanceWithDiscount: decimal &lt;span style="color: blue"&gt;-&amp;gt; &lt;/span&gt;decimal&lt;br /&gt;&lt;span style="color: blue"&gt;end&lt;br /&gt;&lt;br /&gt;type &lt;/span&gt;Customer = &lt;span style="color: blue"&gt;class&lt;br /&gt;    val &lt;/span&gt;id: int&lt;br /&gt;    &lt;span style="color: blue"&gt;val &lt;/span&gt;name: string&lt;br /&gt;    &lt;span style="color: blue"&gt;val &lt;/span&gt;balance: decimal&lt;br /&gt;    &lt;span style="color: blue"&gt;new&lt;/span&gt;(id, name, balance) = &lt;br /&gt;        {id = id; name = name; balance = balance}&lt;br /&gt;    &lt;span style="color: blue"&gt;interface &lt;/span&gt;ICustomer &lt;span style="color: blue"&gt;with&lt;br /&gt;        member &lt;/span&gt;this.Id &lt;br /&gt;            &lt;span style="color: blue"&gt;with &lt;/span&gt;get () = this.id&lt;br /&gt;        &lt;span style="color: blue"&gt;member &lt;/span&gt;this.Name&lt;br /&gt;            &lt;span style="color: blue"&gt;with &lt;/span&gt;get () = this.name&lt;br /&gt;        &lt;span style="color: blue"&gt;member &lt;/span&gt;this.CalculateBalanceWithDiscount discount =&lt;br /&gt;            this.balance - (discount * this.balance)&lt;br /&gt;    &lt;span style="color: blue"&gt;end&lt;br /&gt;end&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;C# Customer Data Access Object Test:&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;TestMethod&lt;/span&gt;]&lt;br /&gt;&lt;span style="color: blue"&gt;public void &lt;/span&gt;CanGetCustomerById()&lt;br /&gt;{&lt;br /&gt;    FSharpMockExample.Data.&lt;span style="color: #2b91af"&gt;ICustomerDao &lt;/span&gt;customerDao = &lt;span style="color: blue"&gt;new &lt;/span&gt;FSharpMockExample.Data.&lt;span style="color: #2b91af"&gt;CustomerDao&lt;/span&gt;();&lt;br /&gt;    FSharpMockExample.Entities.&lt;span style="color: #2b91af"&gt;ICustomer &lt;/span&gt;customer = customerDao.GetById(1);&lt;br /&gt;    &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.AreEqual(customer.Id, 1);&lt;br /&gt;    &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.AreEqual(customer.Name, &lt;span style="color: #a31515"&gt;&amp;quot;ABC Company&amp;quot;&lt;/span&gt;);&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;F# Customer Data Access Object:&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Signature File:&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;#light&lt;br /&gt;namespace &lt;/span&gt;FSharpMockExample.Data&lt;br /&gt;&lt;span style="color: blue"&gt;open &lt;/span&gt;FSharpMockExample.Entities&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue"&gt;type &lt;/span&gt;ICustomerDao = &lt;span style="color: blue"&gt;interface&lt;br /&gt;    abstract &lt;/span&gt;GetById: int &lt;span style="color: blue"&gt;-&amp;gt; &lt;/span&gt;ICustomer&lt;br /&gt;&lt;span style="color: blue"&gt;end&lt;br /&gt;&lt;br /&gt;type &lt;/span&gt;CustomerDao = &lt;span style="color: blue"&gt;class&lt;br /&gt;    new&lt;/span&gt;: unit &lt;span style="color: blue"&gt;-&amp;gt; &lt;/span&gt;CustomerDao&lt;br /&gt;    &lt;span style="color: blue"&gt;interface &lt;/span&gt;ICustomerDao&lt;br /&gt;&lt;span style="color: blue"&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Source File:&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;#light&lt;br /&gt;namespace &lt;/span&gt;FSharpMockExample.Data&lt;br /&gt;&lt;span style="color: blue"&gt;open &lt;/span&gt;FSharpMockExample.Entities&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue"&gt;type &lt;/span&gt;ICustomerDao = &lt;span style="color: blue"&gt;interface&lt;br /&gt;    abstract &lt;/span&gt;GetById: int &lt;span style="color: blue"&gt;-&amp;gt; &lt;/span&gt;ICustomer&lt;br /&gt;&lt;span style="color: blue"&gt;end&lt;br /&gt;&lt;br /&gt;type &lt;/span&gt;CustomerDao = &lt;span style="color: blue"&gt;class&lt;br /&gt;    new&lt;/span&gt;()={}&lt;br /&gt;    &lt;span style="color: blue"&gt;interface &lt;/span&gt;ICustomerDao &lt;span style="color: blue"&gt;with&lt;br /&gt;        member &lt;/span&gt;this.GetById id =&lt;br /&gt;            &lt;span style="color: blue"&gt;new &lt;/span&gt;Customer(id, &lt;span style="color: maroon"&gt;&amp;quot;ABC Company&amp;quot;&lt;/span&gt;, 20.00M) :&amp;gt; ICustomer&lt;br /&gt;&lt;span style="color: blue"&gt;end&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;C# Customer Service Test:&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;[&lt;span style="color: #2b91af"&gt;TestMethod&lt;/span&gt;]&lt;br /&gt;&lt;span style="color: blue"&gt;public void &lt;/span&gt;CanCalculateBalance()&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: blue"&gt;var &lt;/span&gt;mocks = &lt;span style="color: blue"&gt;new &lt;/span&gt;&lt;span style="color: #2b91af"&gt;MockRepository&lt;/span&gt;();&lt;br /&gt;    &lt;span style="color: blue"&gt;var &lt;/span&gt;customerDao = mocks.CreateMock&amp;lt;FSharpMockExample.Data.&lt;span style="color: #2b91af"&gt;ICustomerDao&lt;/span&gt;&amp;gt;();&lt;br /&gt;    FSharpMockExample.Entities.&lt;span style="color: #2b91af"&gt;ICustomer &lt;/span&gt;customer = &lt;span style="color: blue"&gt;new &lt;/span&gt;FSharpMockExample.Entities.&lt;span style="color: #2b91af"&gt;Customer&lt;/span&gt;(1, &lt;span style="color: #a31515"&gt;&amp;quot;XYZ Company&amp;quot;&lt;/span&gt;, 50);&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: blue"&gt;using &lt;/span&gt;(mocks.Record())&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: #2b91af"&gt;Expect&lt;/span&gt;.Call(customerDao.GetById(1)).IgnoreArguments().Return(customer);&lt;br /&gt;    }&lt;br /&gt;&lt;br /&gt;    &lt;span style="color: blue"&gt;using &lt;/span&gt;(mocks.Playback())&lt;br /&gt;    {&lt;br /&gt;        &lt;span style="color: blue"&gt;int &lt;/span&gt;customerId = 1;&lt;br /&gt;        &lt;span style="color: blue"&gt;decimal &lt;/span&gt;discount = .1M;&lt;br /&gt;        FSharpMockExample.Services.&lt;span style="color: #2b91af"&gt;ICustomerService &lt;/span&gt;customerService = &lt;span style="color: blue"&gt;new &lt;/span&gt;FSharpMockExample.Services.&lt;span style="color: #2b91af"&gt;CustomerService&lt;/span&gt;(customerDao);&lt;br /&gt;        &lt;span style="color: blue"&gt;var &lt;/span&gt;balanceWithDiscount = customerService.CalculateBalaceWithDiscount(customerId, discount);&lt;br /&gt;&lt;br /&gt;        &lt;span style="color: #2b91af"&gt;Assert&lt;/span&gt;.AreEqual(balanceWithDiscount, 45);&lt;br /&gt;    }&lt;br /&gt;}&lt;/pre&gt;&lt;br /&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;F# Customer Service:&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Signature File:&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;#light&lt;br /&gt;namespace &lt;/span&gt;FSharpMockExample.Services&lt;br /&gt;&lt;span style="color: blue"&gt;open &lt;/span&gt;FSharpMockExample.Data&lt;br /&gt;&lt;span style="color: blue"&gt;open &lt;/span&gt;FSharpMockExample.Entities&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue"&gt;type &lt;/span&gt;ICustomerService = &lt;span style="color: blue"&gt;interface&lt;br /&gt;    abstract &lt;/span&gt;CalculateBalaceWithDiscount: int*decimal &lt;span style="color: blue"&gt;-&amp;gt; &lt;/span&gt;decimal&lt;br /&gt;&lt;span style="color: blue"&gt;end&lt;br /&gt;&lt;br /&gt;type &lt;/span&gt;CustomerService = &lt;span style="color: blue"&gt;class&lt;br /&gt;    new&lt;/span&gt;: unit &lt;span style="color: blue"&gt;-&amp;gt; &lt;/span&gt;CustomerService&lt;br /&gt;    &lt;span style="color: blue"&gt;new&lt;/span&gt;: ICustomerDao &lt;span style="color: blue"&gt;-&amp;gt; &lt;/span&gt;CustomerService &lt;br /&gt;&lt;span style="color: blue"&gt;end&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;&lt;strong&gt;Source File:&lt;/strong&gt;&lt;/p&gt;&lt;br /&gt;&lt;br /&gt;&lt;pre class="code"&gt;&lt;span style="color: blue"&gt;#light&lt;br /&gt;namespace &lt;/span&gt;FSharpMockExample.Services&lt;br /&gt;&lt;span style="color: blue"&gt;open &lt;/span&gt;FSharpMockExample.Data&lt;br /&gt;&lt;span style="color: blue"&gt;open &lt;/span&gt;FSharpMockExample.Entities&lt;br /&gt;&lt;br /&gt;&lt;span style="color: blue"&gt;type &lt;/span&gt;ICustomerService = &lt;span style="color: blue"&gt;interface&lt;br /&gt;    abstract &lt;/span&gt;CalculateBalaceWithDiscount: int*decimal &lt;span style="color: blue"&gt;-&amp;gt; &lt;/span&gt;decimal&lt;br /&gt;&lt;span style="color: blue"&gt;end&lt;br /&gt;&lt;br /&gt;type &lt;/span&gt;CustomerService = &lt;span style="color: blue"&gt;class&lt;br /&gt;    val &lt;/span&gt;customerDao: ICustomerDao&lt;br /&gt;    &lt;span style="color: blue"&gt;new &lt;/span&gt;(customerDao) = &lt;br /&gt;        {customerDao = customerDao}&lt;br /&gt;    &lt;span style="color: blue"&gt;new &lt;/span&gt;() = &lt;br /&gt;        {customerDao = &lt;span style="color: blue"&gt;new &lt;/span&gt;CustomerDao()}&lt;br /&gt;    &lt;span style="color: blue"&gt;interface &lt;/span&gt;ICustomerService &lt;span style="color: blue"&gt;with&lt;br /&gt;        member &lt;/span&gt;this.CalculateBalaceWithDiscount (customerId, discount) =&lt;br /&gt;            &lt;span style="color: blue"&gt;let &lt;/span&gt;customer = &lt;br /&gt;                this.customerDao.GetById(customerId)&lt;br /&gt;            customer.CalculateBalanceWithDiscount(discount)    &lt;br /&gt;    &lt;span style="color: blue"&gt;end&lt;br /&gt;end&lt;/span&gt;&lt;/pre&gt;&lt;br /&gt;&lt;a href="http://11011.net/software/vspaste"&gt;&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;p&gt;Hopefully, this example will inspire you to go out an give this amazing language a try.&lt;/p&gt;  &lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-1381007471654403296?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/1381007471654403296/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=1381007471654403296" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/1381007471654403296?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/1381007471654403296?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/_w9P8QgmQ0g/mocking-f.html" title="Mocking F#" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2008/10/mocking-f.html</feedburner:origLink></entry><entry gd:etag="W/&quot;C0UHRXc5eCp7ImA9WxRWEE0.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-8914458701622465912</id><published>2008-10-25T22:21:00.000-07:00</published><updated>2008-10-25T23:07:14.920-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-10-25T23:07:14.920-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="F#" /><category scheme="http://www.blogger.com/atom/ns#" term="Seq.sum" /><category scheme="http://www.blogger.com/atom/ns#" term="Seq" /><title>F# Seq Module</title><content type="html">Many of the features that make F# so powerful, are the modules that make up the FSLib library.  One of my favorites is the Seq module which can be found in &lt;span class="fixed"&gt;Microsoft.FSharp.Collections namespace.&lt;br /&gt;&lt;br /&gt;This simple example demonstrates how to use the "sum" function of the Seq module.  In this example, four integers are added together.  The result is then squared.&lt;br /&gt;&lt;br /&gt;Note: I have chosen to write these sample tests in C# to help emphasis the interoperability of the languages.  These tests could have just as easily been written in F#.  For examples of this, check out the book &lt;a href="http://www.amazon.com/Expert-F-Experts-Voice-Net/dp/1590598504/ref=sr_1_1?ie=UTF8&amp;amp;s=books&amp;amp;qid=1224999721&amp;amp;sr=8-1"&gt;Expert F#&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Test:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;        [&lt;span style="color: rgb(0, 204, 204);"&gt;TestMethod&lt;/span&gt;]&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;        public void&lt;/span&gt; CanCalculateSeqExample()&lt;br /&gt;        {&lt;br /&gt;            &lt;span style="color: rgb(0, 204, 204);"&gt;List&lt;/span&gt;&lt;&lt;span style="color: rgb(51, 51, 255);"&gt;int&lt;/span&gt;&gt; numbersToCalculate = &lt;span style="color: rgb(51, 51, 255);"&gt;new &lt;/span&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;List&lt;/span&gt;&lt;&lt;span style="color: rgb(51, 51, 255);"&gt;int&lt;/span&gt;&gt;();&lt;br /&gt;            numbersToCalculate.Add(1);&lt;br /&gt;            numbersToCalculate.Add(2);&lt;br /&gt;            numbersToCalculate.Add(3);&lt;br /&gt;            numbersToCalculate.Add(4);&lt;br /&gt;            &lt;span style="color: rgb(51, 51, 255);"&gt;int &lt;/span&gt;result = &lt;span style="color: rgb(0, 204, 204);"&gt;FSharpSample&lt;/span&gt;.CalculateSeqExample(numbersToCalculate);&lt;br /&gt;&lt;br /&gt;            &lt;span style="color: rgb(0, 204, 204);"&gt;Assert&lt;/span&gt;.AreEqual(result, 100);&lt;br /&gt;        }&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;.fs File:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;#light&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;let &lt;/span&gt;CalculateNumberSquared x = x*x&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;let &lt;/span&gt;CalculateSeqExample args =&lt;br /&gt;    Seq.sum args |&gt; CalculateNumberSquared&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;.fsi File:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;#light&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;val &lt;/span&gt;CalculateNumberSquared: int -&gt; int&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;val &lt;/span&gt;CalculateSeqExample: seq&lt;int&gt; -&gt; int&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Explanation:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;While this example is very simple, it provides a brief view into the power that some of these modules provides.  This example also shows how functions can be chained together.  The astute observer will have noticed the "|&gt;" operator in the &lt;/span&gt;&lt;span class="fixed"&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;/span&gt;CalculateSeqExample function.  This &lt;/span&gt;operator is known as the pipe-forward or forward operator.  It allows the result of the preceding function to be forwarded on to the next function in the chain. &lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;span class="fixed"&gt;&lt;br /&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-8914458701622465912?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/8914458701622465912/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=8914458701622465912" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/8914458701622465912?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/8914458701622465912?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/d763xNX4iyc/f-seq-module.html" title="F# Seq Module" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2008/10/f-seq-module.html</feedburner:origLink></entry><entry gd:etag="W/&quot;A0QESHY9eyp7ImA9WxRXFEk.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-5515707352715019577</id><published>2008-10-18T11:58:00.000-07:00</published><updated>2008-10-19T13:48:29.863-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-10-19T13:48:29.863-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="IL" /><category scheme="http://www.blogger.com/atom/ns#" term="F#" /><category scheme="http://www.blogger.com/atom/ns#" term="MSIL" /><title>Comparing MSIL of F# Versus C#</title><content type="html">&lt;p&gt;&lt;span style="font-weight: bold;"&gt;Comparing MSIL:&lt;/span&gt;&lt;br /&gt;&lt;/p&gt;&lt;p&gt;To get a good understanding of what is going on "under the covers" of our example from last week, a person can view the generated MSIL (Microsoft Intermediate Language).  While there are several options for doing this, I chose to use &lt;a href="http://www.red-gate.com/products/reflector/"&gt;Reflector&lt;/a&gt;.&lt;br /&gt;&lt;/p&gt;&lt;p&gt;Here's a review of the F# code as well as the C# equivalent:&lt;br /&gt;&lt;/p&gt;&lt;p&gt;  F#:  &lt;/p&gt;Test:&lt;br /&gt;&lt;p&gt;[&lt;span style="color: rgb(0, 204, 204);"&gt;TestMethod&lt;/span&gt;]&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;public void&lt;/span&gt; CanCalculateNumberSquared()&lt;br /&gt;{ &lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br /&gt;int &lt;/span&gt;result = &lt;span style="color: rgb(0, 204, 204);"&gt;FSharpSample&lt;/span&gt;.CalculateNumberSquared(2); &lt;span style="color: rgb(0, 204, 204);"&gt;&lt;br /&gt;Assert&lt;/span&gt;.AreEqual(result, 4)&lt;br /&gt;}  &lt;/p&gt;&lt;p&gt;Code: &lt;/p&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;#light&lt;/span&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br /&gt;let&lt;/span&gt; CalculateNumberSquared x = x*x;;&lt;br /&gt;&lt;p&gt;Here's the C# code.  &lt;/p&gt;Test:&lt;br /&gt;&lt;p&gt;[&lt;span style="color: rgb(0, 204, 204);"&gt;TestMethod&lt;/span&gt;] &lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br /&gt;public void&lt;/span&gt; CanCalculateNumberSquaredInCSharp()&lt;br /&gt;{&lt;br /&gt;CSharpSample.&lt;span style="color: rgb(0, 204, 204);"&gt;CSharpSample &lt;/span&gt;cSharpSample = &lt;span style="color: rgb(51, 51, 255);"&gt;new &lt;/span&gt;CSharpSample.&lt;span style="color: rgb(0, 204, 204);"&gt;CSharpSample&lt;/span&gt;(); &lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br /&gt;int &lt;/span&gt;result = &lt;span style="color: rgb(0, 204, 204);"&gt;CSharpSample&lt;/span&gt;.CalculateNumberSquared(2); &lt;span style="color: rgb(0, 204, 204);"&gt;&lt;br /&gt;Assert&lt;/span&gt;.AreEqual(result, 4);&lt;br /&gt;}  &lt;/p&gt;Code:&lt;br /&gt;&lt;p&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;public class&lt;/span&gt; &lt;span style="color: rgb(0, 204, 204);"&gt;CSharpSample&lt;/span&gt;&lt;br /&gt;{ &lt;span style="color: rgb(51, 51, 255);"&gt;    &lt;br /&gt;public int&lt;/span&gt; CalculateNumberSquared(&lt;span style="color: rgb(51, 51, 255);"&gt;int &lt;/span&gt;numberToSquare)&lt;br /&gt;{ &lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br /&gt;return &lt;/span&gt;numberToSquare * numberToSquare;&lt;br /&gt;}&lt;br /&gt;}  &lt;/p&gt;Here is the managed code with comments explaining what is happening:&lt;br /&gt;&lt;p&gt;&lt;br /&gt;C#:&lt;/p&gt; &lt;table&gt;&lt;tbody&gt; &lt;tr&gt; &lt;td style="padding: 4px 5px;" colspan="2" valign="top"&gt;&lt;pre&gt;&lt;span style="color: rgb(16, 0, 160);"&gt;.method&lt;/span&gt; &lt;span style="color: rgb(16, 0, 160);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(16, 0, 160);"&gt;hidebysig&lt;/span&gt; &lt;span style="color: rgb(16, 0, 160);"&gt;instance&lt;/span&gt; &lt;a title="int32" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"&gt;int32&lt;/a&gt; &lt;b&gt;&lt;a class="bold" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://CSharpSample:1.0.0.0/CSharpSample.CSharpSample/CalculateNumberSquared%28Int32%29:Int32"&gt;CalculateNumberSquared&lt;/a&gt;&lt;/b&gt;(&lt;a title="int32" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"&gt;int32&lt;/a&gt; numberToSquare)&lt;span style="color: rgb(16, 0, 160);"&gt; &lt;/span&gt;&lt;span style="color: rgb(16, 0, 160);"&gt;cil&lt;/span&gt;&lt;span style="color: rgb(16, 0, 160);"&gt; &lt;/span&gt;&lt;span style="color: rgb(16, 0, 160);"&gt;managed&lt;/span&gt; {     &lt;span style="color: rgb(16, 0, 160);"&gt;&lt;br /&gt;.maxstack&lt;/span&gt; 2 &lt;span style="color: rgb(0, 153, 0);"&gt;// maximum number of elements that can be pushed to the valuation stack&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(16, 0, 160);"&gt;.locals&lt;/span&gt; &lt;span style="color: rgb(16, 0, 160);"&gt;init&lt;/span&gt; (&lt;br /&gt;[&lt;span style="color: rgb(128, 0, 0);"&gt;0&lt;/span&gt;] &lt;a title="int32" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"&gt;int32&lt;/a&gt; &lt;b&gt;CS$1$0000&lt;/b&gt;) &lt;span style="color: rgb(0, 153, 0);"&gt;// this is a local variable of type int32    &lt;/span&gt;&lt;br /&gt;L_0000: &lt;a title="nop (0x0000): Fills space if bytecodes are patched. No meaningful operation is performed although a processing cycle can be consumed."&gt;nop&lt;/a&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;// do nothing -- indicates compiled in debug mode&lt;/span&gt;&lt;br /&gt;L_0001: &lt;a title="ldarg.1 (0x0003): Loads the argument at index 1 onto the evaluation stack."&gt;ldarg.1&lt;/a&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;// push argument 1 onto the stack     &lt;/span&gt;&lt;br /&gt;L_0002: &lt;a title="ldarg.1 (0x0003): Loads the argument at index 1 onto the evaluation stack."&gt;ldarg.1&lt;/a&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;// push argument 1 onto the stack (multiplying a number by itself)    &lt;/span&gt;&lt;br /&gt;L_0003: &lt;a title="mul (0x005a): Multiplies two values and pushes the result on the evaluation stack."&gt;mul&lt;/a&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;// multiply values&lt;/span&gt;&lt;br /&gt;L_0004: &lt;a title="stloc.0 (0x000a): Pops the current value from the top of the evaluation stack and stores it in a the local variable list at index 0."&gt;stloc.0&lt;/a&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;// pop a value from the stack into a local variable &lt;/span&gt;&lt;br /&gt;L_0005: &lt;a title="br.s (0x002b): Unconditionally transfers control to a target instruction (short form)."&gt;br.s&lt;/a&gt; L_0007 &lt;span style="color: rgb(0, 153, 0);"&gt;// go to labl L_0007&lt;/span&gt;&lt;br /&gt;L_0007: &lt;a title="ldloc.0 (0x0006): Loads the local variable at index 0 onto the evaluation stack."&gt;ldloc.0&lt;/a&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;// push local variable at index 0 onto the stack&lt;/span&gt;&lt;br /&gt;L_0008: &lt;a title="ret (0x002a): Returns from the current method, pushing a return value (if present) from the caller's evaluation stack onto the callee's evaluation stack."&gt;ret&lt;/a&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;// return the value from the stack (if there is one) and return from the method&lt;br /&gt;&lt;/span&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;F#:&lt;br /&gt;&lt;br /&gt;&lt;table&gt;&lt;br /&gt;&lt;tbody&gt; &lt;tr&gt; &lt;td colspan="2" style="padding: 4px 5px;" valign="top" width="980"&gt;&lt;pre&gt;&lt;span style="color: rgb(16, 0, 160);"&gt;.method&lt;/span&gt; &lt;span style="color: rgb(16, 0, 160);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(16, 0, 160);"&gt;static&lt;/span&gt; &lt;a title="int32" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"&gt;int32&lt;/a&gt; &lt;b&gt;&lt;a class="bold" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://FSharpSample/FSharpSample/CalculateNumberSquared%28Int32%29:Int32"&gt;CalculateNumberSquared&lt;/a&gt;&lt;/b&gt;(&lt;a title="int32" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"&gt;int32&lt;/a&gt; x)&lt;span style="color: rgb(16, 0, 160);"&gt; &lt;/span&gt;&lt;span style="color: rgb(16, 0, 160);"&gt;cil&lt;/span&gt;&lt;span style="color: rgb(16, 0, 160);"&gt; &lt;/span&gt;&lt;span style="color: rgb(16, 0, 160);"&gt;managed&lt;/span&gt; {     &lt;span style="color: rgb(16, 0, 160);"&gt;&lt;br /&gt;.maxstack&lt;/span&gt; 4 &lt;span style="color: rgb(0, 153, 0);"&gt;// maximum number of elements that can be pushed to the valuation stack&lt;/span&gt;&lt;br /&gt;L_0000: &lt;a title="nop (0x0000): Fills space if bytecodes are patched. No meaningful operation is performed although a processing cycle can be consumed."&gt;nop&lt;/a&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;// do nothing -- indicates compiled in debug mode&lt;/span&gt;&lt;br /&gt;L_0001: &lt;a title="ldarg.0 (0x0002): Loads the argument at index 0 onto the evaluation stack."&gt;ldarg.0&lt;/a&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;// push argument 0 onto the stack     &lt;/span&gt;&lt;br /&gt;L_0002: &lt;a title="ldarg.0 (0x0002): Loads the argument at index 0 onto the evaluation stack."&gt;ldarg.0&lt;/a&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;// push argument 0 onto the stack     &lt;/span&gt;&lt;br /&gt;L_0003: &lt;a title="mul (0x005a): Multiplies two values and pushes the result on the evaluation stack."&gt;mul&lt;/a&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;// multiply values&lt;/span&gt;&lt;br /&gt;L_0004: &lt;a title="ret (0x002a): Returns from the current method, pushing a return value (if present) from the caller's evaluation stack onto the callee's evaluation stack."&gt;ret&lt;/a&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;// return the value from the stack (if there is one) and return from the method&lt;br /&gt;&lt;/span&gt;}&lt;span style="color: rgb(0, 153, 0);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/pre&gt;&lt;div style="text-align: left;"&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="font-size:100%;"&gt;This first thing that I noticed when comparing the managed code from each example, was that&lt;br /&gt;the F# code is more succinct.  Each is accomplishing the same goal, but the CIL generated from&lt;br /&gt;F# is five lines less that that which was generated from the C# example.  &lt;/span&gt;The second thing I&lt;br /&gt;noticed was that the F# method is static while the C# method is not.  To ensure that we are&lt;br /&gt;comparing apples to apples, a new static method was generated in the C# example.    &lt;/p&gt;&lt;br /&gt;&lt;p&gt;Here's the code:    &lt;/p&gt;&lt;br /&gt;&lt;p&gt;Test: &lt;/p&gt;&lt;br /&gt;&lt;p&gt;&lt;span style="color: rgb(0, 204, 204);"&gt;&lt;span style="color: rgb(0, 0, 0);"&gt;[&lt;/span&gt;TestMethod&lt;span style="color: rgb(0, 0, 0);"&gt;]&lt;/span&gt;&lt;/span&gt;&lt;br /&gt; &lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br /&gt;public void&lt;/span&gt; CanStaticCalculateNumberSquaredInCSharp()&lt;br /&gt;&lt;br /&gt;{ &lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br /&gt;int &lt;/span&gt;result = CSharpSample.&lt;span style="color: rgb(0, 204, 204);"&gt;StaticCSharpSample&lt;/span&gt;.CalculateNumberSquared(2); &lt;span style="color: rgb(0, 204, 204);"&gt;&lt;br /&gt;Assert&lt;/span&gt;.AreEqual(result, 4);&lt;br /&gt;&lt;br /&gt;}    &lt;/p&gt;&lt;br /&gt;&lt;p&gt;Code: &lt;/p&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;public static class&lt;/span&gt; &lt;span style="color: rgb(0, 204, 204);"&gt;StaticCSharpSample&lt;/span&gt;&lt;p&gt;{ &lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br /&gt;&lt;/span&gt;&lt;/p&gt;&lt;p&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;public static int&lt;/span&gt; CalculateNumberSquared(&lt;span style="color: rgb(51, 51, 255);"&gt;int &lt;/span&gt;numberToSquare)&lt;br /&gt;{ &lt;span style="color: rgb(51, 51, 255);"&gt;&lt;br /&gt;return &lt;/span&gt;numberToSquare * numberToSquare;&lt;br /&gt;}&lt;br /&gt;}    &lt;/p&gt;MSIL:&lt;br /&gt;&lt;table style="margin-bottom: 0px;" width="100%" cellpadding="0" cellspacing="0"&gt; &lt;tbody&gt; &lt;tr&gt; &lt;td style="padding: 4px 5px;" colspan="2" valign="top"&gt;&lt;pre&gt;&lt;span style="color: rgb(16, 0, 160);"&gt;.method&lt;/span&gt; &lt;span style="color: rgb(16, 0, 160);"&gt;public&lt;/span&gt; &lt;span style="color: rgb(16, 0, 160);"&gt;hidebysig&lt;/span&gt; &lt;span style="color: rgb(16, 0, 160);"&gt;static&lt;/span&gt; &lt;a title="int32" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"&gt;int32&lt;/a&gt; &lt;b&gt;&lt;a class="bold" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://CSharpSample:1.0.0.0/CSharpSample.StaticCSharpSample/CalculateNumberSquared%28Int32%29:Int32"&gt;CalculateNumberSquared&lt;/a&gt;&lt;/b&gt;(&lt;a title="int32" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"&gt;int32&lt;/a&gt; numberToSquare)&lt;span style="color: rgb(16, 0, 160);"&gt; &lt;/span&gt;&lt;span style="color: rgb(16, 0, 160);"&gt;cil&lt;/span&gt;&lt;span style="color: rgb(16, 0, 160);"&gt; &lt;/span&gt;&lt;span style="color: rgb(16, 0, 160);"&gt;managed&lt;/span&gt; {     &lt;span style="color: rgb(16, 0, 160);"&gt;&lt;br /&gt;.maxstack&lt;/span&gt; 2 &lt;span style="color: rgb(0, 153, 0);"&gt;// maximum number of elements that can be pushed to the valuation stack&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(16, 0, 160);"&gt;.locals&lt;/span&gt; &lt;span style="color: rgb(16, 0, 160);"&gt;init&lt;/span&gt; (&lt;br /&gt; [&lt;span style="color: rgb(128, 0, 0);"&gt;0&lt;/span&gt;] &lt;a title="int32" href="http://www.aisto.com/roeder/dotnet/Default.aspx?Target=code://mscorlib:2.0.0.0:b77a5c561934e089/System.Int32"&gt;int32&lt;/a&gt; &lt;b&gt;CS$1$0000&lt;/b&gt;) &lt;span style="color: rgb(0, 153, 0);"&gt;// this is a local variable of type int32    &lt;/span&gt;&lt;br /&gt;L_0000: &lt;a title="nop (0x0000): Fills space if bytecodes are patched. No meaningful operation is performed although a processing cycle can be consumed."&gt;nop&lt;/a&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;// do nothing -- indicates compiled in debug mode&lt;/span&gt;    &lt;br /&gt;L_0001: &lt;a title="ldarg.1 (0x0003): Loads the argument at index 1 onto the evaluation stack."&gt;ldarg.1&lt;/a&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;// push argument 1 onto the stack     &lt;/span&gt;&lt;br /&gt;L_0002: &lt;a title="ldarg.1 (0x0003): Loads the argument at index 1 onto the evaluation stack."&gt;ldarg.1&lt;/a&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;// push argument 1 onto the stack multiplying a number by itself)    &lt;/span&gt;&lt;br /&gt;L_0003: &lt;a title="mul (0x005a): Multiplies two values and pushes the result on the evaluation stack."&gt;mul&lt;/a&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;// multiply values&lt;/span&gt;&lt;br /&gt;L_0004: &lt;a title="stloc.0 (0x000a): Pops the current value from the top of the evaluation stack and stores it in a the local variable list at index 0."&gt;stloc.0&lt;/a&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;// pop a value from the stack into a local variable &lt;/span&gt;&lt;br /&gt;L_0005: &lt;a title="br.s (0x002b): Unconditionally transfers control to a target instruction (short form)."&gt;br.s&lt;/a&gt; L_0007 &lt;span style="color: rgb(0, 153, 0);"&gt;// go to labl L_0007&lt;/span&gt;&lt;br /&gt;L_0007: &lt;a title="ldloc.0 (0x0006): Loads the local variable at index 0 onto the evaluation stack."&gt;ldloc.0&lt;/a&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;// push local variable at index 0 onto the stack&lt;/span&gt;&lt;br /&gt;L_0008: &lt;a title="ret (0x002a): Returns from the current method, pushing a return value (if present) from the caller's evaluation stack onto the callee's evaluation stack."&gt;ret&lt;/a&gt; &lt;span style="color: rgb(0, 153, 0);"&gt;// return the value from the stack (if there is one) and return from the method&lt;br /&gt;&lt;/span&gt;}&lt;br /&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div style="text-align: left;"&gt;As you can see, the MSIL is very similar to that which was generated in our first example.&lt;br /&gt;While we could probably find a way to make the C# example generate the same managed&lt;br /&gt;code as the F# example, it is clear that the F# example requires less work and less lines of code&lt;br /&gt;to generate the more succinct result.&lt;br /&gt;&lt;/div&gt;&lt;/div&gt;&lt;pre&gt;&lt;/pre&gt;&lt;/td&gt;&lt;/tr&gt;&lt;/tbody&gt;&lt;/table&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-5515707352715019577?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/5515707352715019577/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=5515707352715019577" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/5515707352715019577?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/5515707352715019577?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/LWIh8yLHqeE/comparing-msil-of-f-versus-c.html" title="Comparing MSIL of F# Versus C#" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2008/10/comparing-msil-of-f-versus-c.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0EMQXk7eyp7ImA9WxRXFEk.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-6553073695359362491</id><published>2008-10-18T11:04:00.000-07:00</published><updated>2008-10-19T12:48:00.703-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-10-19T12:48:00.703-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="F#" /><title>Breaking Down The Code</title><content type="html">&lt;span style="font-weight: bold;"&gt;Overview:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;Last week we walked through creating our first F# application using TDD (Test Driven Development).  Today we will break down that first example to identify what each of our commands are doing.&lt;br /&gt;&lt;br /&gt;Here's a review of the extremely simple application that we wrote:&lt;br /&gt;&lt;br /&gt;Test:&lt;br /&gt;[&lt;span style="color: rgb(0, 204, 204);"&gt;TestMethod&lt;/span&gt;]&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;public void&lt;/span&gt; CanCalculateNumberSquared()&lt;br /&gt;{&lt;br /&gt;    &lt;span style="color: rgb(51, 51, 255);"&gt;int &lt;/span&gt;result = &lt;span style="color: rgb(0, 204, 204);"&gt;FSharpSample&lt;/span&gt;.CalculateNumberSquared(2);&lt;br /&gt;    &lt;span style="color: rgb(0, 204, 204);"&gt;Assert&lt;/span&gt;.AreEqual(result, 4);&lt;br /&gt;}&lt;br /&gt;&lt;br /&gt;Code:&lt;br /&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;#light&lt;/span&gt;&lt;br /&gt;&lt;span style="color: rgb(51, 51, 255);"&gt;let&lt;/span&gt; CalculateNumberSquared x = x*x;;&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Breaking Down The Code:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;So what does this all mean?&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;#light&lt;/span&gt;&lt;br /&gt;The #light (pronounced "Hash" light) compiler directive provides various features that simplify the F# language.   It also allows compatibility with the language OCaml.   At the time of this writing, most experts recommend the use of this directive.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Identifiers:&lt;/span&gt;&lt;br /&gt;The "let" keyword allows the programmer to associate any value or formulate to an "Identifier".  Here's how Robert Pickering describes identifiers in his book "&lt;a href="http://www.amazon.com/Foundations-F-Experts-Voice-Net/dp/1590597575/ref=pd_bbs_sr_3?ie=UTF8&amp;amp;s=books&amp;amp;qid=1224355719&amp;amp;sr=8-3"&gt;Foundations of F#&lt;/a&gt;".  "To most people coming from an imperative programming background, this will look like a variable assignment. There are a lot of similarities, but there are key differences. In pure functional programming, once a value is assigned to an identifier, it never changes. This is why I will refer to them throughout this book as &lt;i class="emphasis"&gt;identifiers&lt;/i&gt; and not &lt;i class="emphasis"&gt;variables&lt;/i&gt;."  If you have not read this book, I strongly recommend it.&lt;br /&gt;&lt;br /&gt;In our example, we are setting up an identifier named "CalculateNumberSquared", specifying a parameter named "x", and finally providing instructions on what to do with that parameter.  This identifier can then be passed around to other identifiers and/or functions.&lt;br /&gt;&lt;br /&gt;This ability to pass around functions and identifiers is one of the great features in F#.  While it may take some time to get use to this concept, you will soon wonder how you ever got along without it.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-6553073695359362491?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/6553073695359362491/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=6553073695359362491" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/6553073695359362491?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/6553073695359362491?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/dB6yBJOloek/breaking-down-code.html" title="Breaking Down The Code" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2008/10/breaking-down-code.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0EASXk_cSp7ImA9WxRXFEk.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-877681868575026889</id><published>2008-10-13T17:53:00.000-07:00</published><updated>2008-10-19T12:47:28.749-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-10-19T12:47:28.749-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="F#" /><category scheme="http://www.blogger.com/atom/ns#" term="TDD" /><title>Getting Started With F#</title><content type="html">First retrieve and install the latest release of F# (the Sept. 2008 CTP can be found &lt;a href="http://www.microsoft.com/downloads/details.aspx?FamilyID=61ad6924-93ad-48dc-8c67-60f7e7803d3c&amp;amp;displaylang=en"&gt;here&lt;/a&gt;).&lt;br /&gt;&lt;br /&gt;I'm a believer in TDD (Test Driven Development), so our first step after installation of the CTP is to create a test.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 1: Creating the Test Project:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1. Open Visual Studio and type Ctrl+Shift+N to create a new project.&lt;br /&gt;2. Create a Test project by selecting a project type of Visual C#\Test\Test Project. ( Note: I'm using a C# test project in VS2008, but any other test project will do.)&lt;br /&gt;3. Set the location to any desired path with a new destination folder of "FSharpGettingStarted".&lt;br /&gt;4. Change the Name to "FSharpTests".&lt;br /&gt;5. Ensure that "Create New Solution" is selected and that "Create Directory For Solution" is checked.&lt;br /&gt;6. Click OK.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 2: Creating the First Test:&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1. Delete the default class that was generated in the test project.&lt;br /&gt;2. Right click the FSharpTests project and select "Add\New Test...".&lt;br /&gt;3. Select the Unit Test template and set the Test Name to "FSharpSampleTests.cs" then click OK.&lt;br /&gt;4. In the newly generated class, locate the method "TestMethod1" and rename it to CanCalculateNumberSquared.&lt;br /&gt;5. Remove the text that was generated in the method and type:&lt;br /&gt;        int result = FSharpSample.CalculateNumberSquared(2);&lt;br /&gt;        Assert.AreEqual(result, 4);&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 3: Creating the F# project:&lt;/span&gt;&lt;br /&gt;1. Type Ctrl+Shift+N and select the project type of Visual F#\F# Library.&lt;br /&gt;2. Change the name to "FSharpSample".&lt;br /&gt;3. Change the Solution option to "Add to Solution" and click OK.&lt;br /&gt;&lt;br /&gt;&lt;span style="font-weight: bold;"&gt;Step 4: Adding the F# Function From Our Test:&lt;/span&gt;&lt;br /&gt;1. Delete the "Module1.fs" file that was generated.&lt;br /&gt;2. Right click on the FSharpSample project and select Add\New Item\F# Signature File.&lt;br /&gt;3. Name the file "FSharpSample.fsi".&lt;br /&gt;4. Right click on the FSharpSample project and select Add\New Item\F# Source File.&lt;br /&gt;5. Name the file "FSharpSample.fs".  (Note: if you add the ".fs" file before the ".fsi" file you may see an error message that states "An implementation of file or module FSharpSample has already been given. Compilation order is significant in F# because of type inference. You may need to adjust the order of your files to place the signature file before the implementation.".  If you see this error, simply delete the ".fs" file and recreate it or manually edit the ".fsproj" file so that the ".fsi" file reference is above the ".fs" file reference in the ItemGroups.)&lt;br /&gt;6. Open the FSharpSample.fsi file and type "val CalculateNumberSquared: int -&gt; int" in the line directly below the line that states "#light".&lt;br /&gt;7. Open the FSharpSample.fs file and type "let CalculateNumberSquared x = x*x;;" in the line directly below the line that states "#light".&lt;br /&gt;8. Add the FSharpSample project as a reference to your Test project.&lt;br /&gt;7. Run your test and it should now pass.&lt;br /&gt;&lt;br /&gt;That's all there is to setting up your first F# library created with TDD.  Next we will start talking about what some of this all means.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-877681868575026889?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/877681868575026889/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=877681868575026889" title="1 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/877681868575026889?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/877681868575026889?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/ToY9Sx0FAgA/getting-started-with-f.html" title="Getting Started With F#" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">1</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2008/10/getting-started-with-f.html</feedburner:origLink></entry><entry gd:etag="W/&quot;Ck8MSXk7cSp7ImA9WxRXFEo.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-9092765159416492957</id><published>2008-10-12T11:54:00.000-07:00</published><updated>2008-10-19T19:48:08.709-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-10-19T19:48:08.709-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="Why F#" /><category scheme="http://www.blogger.com/atom/ns#" term="F# versus C#" /><category scheme="http://www.blogger.com/atom/ns#" term="F# vs. C#" /><title>F# Versus C#, VB, and Other .NET Languages</title><content type="html">&lt;span style="FONT-WEIGHT: bold"&gt;Why F#? What does F# provide that C#, VB, etc. does not? &lt;/span&gt;&lt;br /&gt;&lt;br /&gt;1. By default, F# uses immutable types, which means that once a type is created, it will not change. This behavior makes the language inherently safe for concurrent operations. With an ever increasing need for concurrency support in enterprise applications, this behavior is becoming more and more desirable. With F#, concurrency related errors such as race conditions, synchronization issues, lock convoys, and deadlocks will be greatly reduced.&lt;br /&gt;&lt;br /&gt;2. F# is built on the concept of functions rather than objects. While objects are supported, functions are also first class citizens. Functions can be and passed around like objects in C#/VB. This makes the language extremely well suited for algorithmic computations and makes it easier to achieve efficient processing of lists of data. Since everything compiles to IL, similar performance on these operations could conceivably be achieved with any .NET language, but F# allows optimal performance for specific operations with much less code. Note: In addition to the new abilities, you still have all functionality available in the .NET framework.&lt;br /&gt;&lt;br /&gt;3. One of the features of F#, that I have found extremely useful, is the interactive scripting functionality. This allows the developer to select a subset of code and run it like a script. Anyone with a background it SQL will find this functionality very easy to understand and extremely useful for learning/experimenting with the language.&lt;br /&gt;&lt;br /&gt;4. Finally, anyone with experience in C# will be thrilled to learn that the immutable aspects of F# will greatly reduce or eliminate the dreaded "Object reference not set to an instance of an object" error.&lt;br /&gt;&lt;br /&gt;Note: F# should be added as an addition to an engineer's arsenal, not a replacement for the existing language of choice. My philosophy has always been, use the tool that is best suited for the task. Use F# in places where it can accomplish the task better and/or easier than the other available options.&lt;br /&gt;&lt;br /&gt;Many of the points listed here are based on comments/documentation from the following:&lt;br /&gt;&lt;br /&gt;&lt;a href="http://msdn.microsoft.com/en-us/fsharp/default.aspx"&gt;http://msdn.microsoft.com/en-us/fsharp/default.aspx&lt;/a&gt;&lt;br /&gt;&lt;br /&gt;Ted Neward: (&lt;a href="http://msdn.microsoft.com/en-us/magazine/cc164244.aspx"&gt;http://msdn.microsoft.com/en-us/magazine/cc164244.aspx&lt;/a&gt;,&lt;br /&gt;&lt;a href="http://www.dotnetrocks.com/default.aspx?showNum=377"&gt;http://www.dotnetrocks.com/default.aspx?showNum=377&lt;/a&gt;)&lt;br /&gt;&lt;br /&gt;The book "Expert F#" (&lt;a href="http://search.barnesandnoble.com/booksearch/isbnInquiry.asp?isbn=1590598504"&gt;http://search.barnesandnoble.com/booksearch/isbnInquiry.asp?isbn=1590598504&lt;/a&gt;)&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-9092765159416492957?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/9092765159416492957/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=9092765159416492957" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/9092765159416492957?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/9092765159416492957?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/kGXG-PYnhWc/f-versus-c-vb-and-other-net-languages.html" title="F# Versus C#, VB, and Other .NET Languages" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2008/10/f-versus-c-vb-and-other-net-languages.html</feedburner:origLink></entry><entry gd:etag="W/&quot;D0AMRXs7fip7ImA9WxRXEEk.&quot;"><id>tag:blogger.com,1999:blog-4853877730213459430.post-7547608950188979396</id><published>2008-10-11T17:34:00.000-07:00</published><updated>2008-10-14T21:43:04.506-07:00</updated><app:edited xmlns:app="http://www.w3.org/2007/app">2008-10-14T21:43:04.506-07:00</app:edited><category scheme="http://www.blogger.com/atom/ns#" term="F#" /><title>What is F#?</title><content type="html">&lt;span style="FONT-WEIGHT: bold"&gt;What is F#?&lt;/span&gt;&lt;br /&gt;&lt;br /&gt;F# is a functional programming language written by Don Syme from Microsoft. In addition to F#, Don has done extensive work on the CLR (Common Language Runtime) and is the main reason that we have generics in C# and VB.NET. F# was built on top of the CLR, which means that it compiles down to IL (Intermediary Language) and is interoperable with all of the other CLR based languages. The Sept. CTP Release is available &lt;a href="http://www.microsoft.com/downloads/details.aspx?familyid=61ad6924-93ad-48dc-8c67-60f7e7803d3c&amp;amp;displaylang=en"&gt;here&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;&lt;span style="FONT-WEIGHT: bold"&gt;What is functional programming?&lt;br /&gt;&lt;br /&gt;&lt;/span&gt;The first functional programming languages--IPL and LISP (which stands for List Programming)--were created in the 1950s. These languages, and all functional programming languages including F#, were built on the foundation of Lambda Calculus. There are many functional programming languages such as OCaml, Erlang, Haskell, and Eiffel. In addition, other languages such as XSLT&lt;br /&gt;are built on some of the concepts from functional languages (note: XSLT is not a functional programming language).&lt;br /&gt;&lt;br /&gt;We have functional programming languages to thank for many of the features that have been released in the .NET Framework such as generics, iterators, and LINQ.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/4853877730213459430-7547608950188979396?l=bloggemdano.blogspot.com'/&gt;&lt;/div&gt;</content><link rel="replies" type="application/atom+xml" href="http://bloggemdano.blogspot.com/feeds/7547608950188979396/comments/default" title="Post Comments" /><link rel="replies" type="text/html" href="https://www.blogger.com/comment.g?blogID=4853877730213459430&amp;postID=7547608950188979396" title="0 Comments" /><link rel="edit" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/7547608950188979396?v=2" /><link rel="self" type="application/atom+xml" href="http://www.blogger.com/feeds/4853877730213459430/posts/default/7547608950188979396?v=2" /><link rel="alternate" type="text/html" href="http://feedproxy.google.com/~r/BloggemDano/~3/U3cTN4fQMTw/what-is-f.html" title="What is F#?" /><author><name>Daniel Mohl</name><uri>http://www.blogger.com/profile/17462870714458080019</uri><email>dmohl@yahoo.com</email><gd:extendedProperty name="OpenSocialUserId" value="05363413153781332816" /></author><thr:total xmlns:thr="http://purl.org/syndication/thread/1.0">0</thr:total><feedburner:origLink>http://bloggemdano.blogspot.com/2008/10/what-is-f.html</feedburner:origLink></entry></feed>
