Chapter 5 of Friendly F# has a great practical explanation of F# computation expressions often called "monads" from their use in computer science and Haskell. The material in Chapter 5 of the book does a lot to demystify the concept, theoretical coverage of which is done well in this Wikipedia article. Monads are an example … Continue reading The Push Monad: Introduction
Author: fierval
Outperforming MathNet with Task Parallel Library
Math.NET is a great project that brings numerics to .NET the OS way. Perusing their blog, I found this post on the on-line algorithm for std calculation. A simple Wiki search revealed this article that describes a parallel algorithm due to Chan for calculating variance (std = sqrt(variance)). So, I set to figure out whether … Continue reading Outperforming MathNet with Task Parallel Library
Fun with F# Charting. Factoring out FSharpChart
FSharpChart wraps .NET 4.0 charting control. Here is Don's entry about it to get started and download the assembly with examples. However, FSharpChart is still a control that needs WinForms or WPF to work. What about some Matlab-esque type of functionality, where a simple function call would do the job without having to worry about … Continue reading Fun with F# Charting. Factoring out FSharpChart
Implementing a Stack in F#. Tail Recursion.
Since Push requires stacks to manipulate its data, we need an implementation of this data structure. There is of course a .NET implementation, however, it is not a "functional" data structure, in a sense that it is mutable. It is easy enough to implement our own, purely functional, immutable stack. F# list is a logical … Continue reading Implementing a Stack in F#. Tail Recursion.
C#/F# Interop and TDD
Since this development was supposed to conform to the best methodology available, I naturally chose Test Driven Development (TDD), which, as the name suggests, presumes writing tests for each piece of the code written. Actually it suggests writing tests first, but who wants to be so dogmatic! I was writing tests at least at the … Continue reading C#/F# Interop and TDD
Push Operation. A Few Words on Computation Expressions/Monads
As we have seen in the previous post, it is easy to implement Push types and operations: Here is an example of an implementation of FLOAT./ operation: a division of two integers on top of the stack. Since in Push an operation is denoted by "OP_TYPE.OP_NAME", it is convenient from the implementation standpoint to group … Continue reading Push Operation. A Few Words on Computation Expressions/Monads
Implementing a Push Type
From a developer's point of view, a Push type is implemented through a class, derived from PushTypeBase, as mentioned in the previous post. Once the type is implemented in any .NET language the system will hook it into the currently available types, will add a parser and a stack for it. All that needs to … Continue reading Implementing a Push Type
Defining a Base for Push Types
Let's take a look at how the base from which all Push types derive is defined. Push types are represented (in all .NET languages) by classes derived from PushTypeBase. This is an abstract class and the listing above shows its definition. Two properties are essential for all classes, deriving from PushTypeBase: • Value – an … Continue reading Defining a Base for Push Types
FParsec: Creating a Parser Dynamically
In one of the previous posts the following definition for parsing simple Push types was discussed: The most noteworthy entry here is pushSimpleTypes. This parser is created dynamically from internally implemented Push types (INTEGER, FLOAT, etc) and may be dynamically extended if it becomes necessary to parse a new type. The dynamic parser is built … Continue reading FParsec: Creating a Parser Dynamically
FParsec: Parsing a List of Dynamic Keywords
In the previous post we mentioned code that parses Push types and Push operations: Tokens for Push types are a dynamic collection of keywords. "Dynamic" in a sense that a developer might add to it when extending the language. We therefore need to create a parser that would recognize tokens from a dynamic set. Since … Continue reading FParsec: Parsing a List of Dynamic Keywords