Correct by Construction in F#http://blogs.msdn.com/b/jomo_fisher/archive/2008/04/22/correct-by-construction-in-f.aspxCorrect by Construction in F#
Jomo Fisher—a theme in the design of the F# language is that problems in the code are revealed as compilation errors. Consider this C# code which is used to compose a courteous letter to a customer:
enum Courtesy {en-USTelligent Evolution Platform Developer Build (Build: 5.6.50428.7875)re: Correct by Construction in F#http://blogs.msdn.com/b/jomo_fisher/archive/2008/04/22/correct-by-construction-in-f.aspx#9700129Thu, 04 Jun 2009 22:31:45 GMT91d46819-8472-40ad-a661-2c78acb4018c:9700129Jonathan Allen<p>&gt; a few special cases </p>
<p>Like everytime you deal with the String type?</p>
<p>F# should have been so much more, but their unwillingness or inability to merge option and null means that my code isn't any safer.</p><div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=9700129" width="1" height="1">re: Correct by Construction in F#http://blogs.msdn.com/b/jomo_fisher/archive/2008/04/22/correct-by-construction-in-f.aspx#8628518Sat, 21 Jun 2008 04:57:23 GMT91d46819-8472-40ad-a661-2c78acb4018c:8628518David Nelson<p>I am curious, how does F# deal with situations where null values are legitimate? Null values in programming languages are similar to null values in databases: they can cause problems if used carelessly, but they do have legitimate uses. And not all classes are well-suited to singleton &quot;empty&quot; values.</p><div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=8628518" width="1" height="1">F# in 20 Minutes – Part IIhttp://blogs.msdn.com/b/jomo_fisher/archive/2008/04/22/correct-by-construction-in-f.aspx#8482369Sat, 10 May 2008 01:19:41 GMT91d46819-8472-40ad-a661-2c78acb4018c:8482369Chris Smith's completely unique view<p>Now that we have covered the basics, in minutes 8 - 14 we will cover the foundational concepts and types</p>
<img src="http://blogs.msdn.com/aggbug.aspx?PostID=8482369" width="1" height="1">re: Correct by Construction in F#http://blogs.msdn.com/b/jomo_fisher/archive/2008/04/22/correct-by-construction-in-f.aspx#8422260Thu, 24 Apr 2008 20:38:33 GMT91d46819-8472-40ad-a661-2c78acb4018c:8422260MichaelGG<p>Blind: Other languages don't know and will pass null; hence with interop you gotta watch it. It's just a sad result of C#/CLS not including some kind of non-nullable type system from the start. </p><div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=8422260" width="1" height="1">re: Correct by Construction in F#http://blogs.msdn.com/b/jomo_fisher/archive/2008/04/22/correct-by-construction-in-f.aspx#8421468Thu, 24 Apr 2008 15:32:08 GMT91d46819-8472-40ad-a661-2c78acb4018c:8421468BlindWanderer@gmail.com<p>I would assume that F# is implicitly adding some non-nullable attribute to it's classes and method parameters. Otherwise how would other languages know not to pass those classes and methods nulls?</p><div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=8421468" width="1" height="1">Community Convergence XLIIIhttp://blogs.msdn.com/b/jomo_fisher/archive/2008/04/22/correct-by-construction-in-f.aspx#8420894Thu, 24 Apr 2008 09:11:02 GMT91d46819-8472-40ad-a661-2c78acb4018c:8420894Charlie Calvert's Community Blog<p>Welcome to the forty-third issue of Community Convergence. The last few weeks have been consumed by the</p>
<img src="http://blogs.msdn.com/aggbug.aspx?PostID=8420894" width="1" height="1">re: Correct by Construction in F#http://blogs.msdn.com/b/jomo_fisher/archive/2008/04/22/correct-by-construction-in-f.aspx#8417896Wed, 23 Apr 2008 06:26:56 GMT91d46819-8472-40ad-a661-2c78acb4018c:8417896MichaelGG<p>Yea, top on my wish list for C# 4 is a non-nullable type system and discriminated unions, hopefully with some primitive pattern matching. But I'm sure I'll just be told to go use F# (which is fine by me, as soon as it's shipping in VS!)</p><div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=8417896" width="1" height="1">re: Correct by Construction in F#http://blogs.msdn.com/b/jomo_fisher/archive/2008/04/22/correct-by-construction-in-f.aspx#8417344Wed, 23 Apr 2008 01:18:05 GMT91d46819-8472-40ad-a661-2c78acb4018c:8417344[ICR]<p>I realise it's not the same and perhaps not in the spirit of the post, but I always write my switch statements in C# as:</p>
<p>switch(Value)</p>
<p>{</p>
<p> &nbsp;case A:</p>
<p> &nbsp; &nbsp;...</p>
<p> &nbsp; &nbsp;break;</p>
<p> &nbsp;case B:</p>
<p> &nbsp; &nbsp;...</p>
<p> &nbsp; &nbsp;break;</p>
<p> &nbsp;default:</p>
<p> &nbsp; &nbsp;Debug.Assert(&quot;ERROR&quot;);</p>
<p>}</p>
<p>Not as good as a compile time but the extra runtime check allows you to catch missing code more often.</p>
<p>But I understand the theme of the post. The non-nullilty of things does help to reduce a lot of errors.</p><div style="clear:both;"></div><img src="http://blogs.msdn.com/aggbug.aspx?PostID=8417344" width="1" height="1">Microsoft news and tips &raquo; Correct by Construction in F#http://blogs.msdn.com/b/jomo_fisher/archive/2008/04/22/correct-by-construction-in-f.aspx#8417229Wed, 23 Apr 2008 00:00:18 GMT91d46819-8472-40ad-a661-2c78acb4018c:8417229Microsoft news and tips &raquo; Correct by Construction in F#<p>PingBack from <a rel="nofollow" target="_new" href="http://microsoftnews.askpcdoc.com/?p=3805">http://microsoftnews.askpcdoc.com/?p=3805</a></p>
<img src="http://blogs.msdn.com/aggbug.aspx?PostID=8417229" width="1" height="1">