Welcome to MSDN Blogs Sign in | Join | Help

January 2008 - Posts

fsyacc Sample on Code Gallery

The first release is a simple four function calculator, which builds off of last week's blog post and integrates fsyacc for parsing. The net result is the ability to write simple simple expressions like "10 * 2 - 15 / 3" and get it evaluated using the order of operations.
Posted by ChrSmith | 1 Comments
Filed under: , ,

Attachment(s): MegaCalc.zip

fslex Sample

In this post I’ll focus on creating a simple program which will take advantage of fslex, and show how to generate a scanner to parse basic mathematical expressions like “1.0 / (sin pi + cos pi)”.
Posted by ChrSmith | 5 Comments
Filed under: , ,

Attachment(s): MegaCalc-fslex-sample.zip

F# Snippet - Enums and Discriminated Unions

I was writing some F# code this week and ran into problem. Consider the following code: type Thingey = This | That | SomethingElse Which looks like an enum. So I assumed that, like things inheriting from System.Enum, an instance of the type had a ToString method which did the right thing. But, alas, when I type it into the F# Interactive Console I get: > (Thingey.That).ToString();; val it : string = "FSI_0002+Thingey" The reason being is that the type Thingey is actually a Discriminated Union. In F#, to produce an Enumeration type you use the same syntax except you must explicitly provide an integer value for each member. Discriminated Unions can do a lot more than Enums in F#, but there are situations in which to use both. The following snippet shows you how to use Enums and simple Discriminated Union types in F#.
Posted by ChrSmith | 1 Comments
Filed under: ,

F# and Markov Chains, oh my!

Recently I started playing a collectable card game after some friends got me into it. (Who themselves got back into it after some friends of theirs started playing. Witness the economic potential of viral card games!) As it turns out, I am a pretty poor card player I figured I would get into the business of collecting cards. Which is fun, you can do alone, and requires no skill. I figured I would answer the question “If I started from scratch, how many booster packs would it take for me to collect the whole set”. Well, since booster packs give you cards randomly the best you can shoot for is a confidence interval.
Posted by ChrSmith | 2 Comments
Filed under: , ,
 
Page view tracker