TP

Imperative computation in F# (I.) - Returning results from a function

One of the limitations of F# is that it doesn't very well support some of the advanced imperative language constructs such as break, continue or imperative style of returning value from a function, meaning that you can't write something like return false in the middle of the function. This has good reasons. F# doesn't in principle have the notion of currently executing statement and instead treat every code you write as an expression. Clearly, when there is no current statement, we cannot jump to other statements. If you're looking for more information about these basic principles, you can take a look at my book Real World Functional Programming, which covers this distinction in details in chapter 2, but we'll look at a brief example that will clarify this idea shortly.

Often, there is really no need to use break or other imperative constructs in F#, because you can write the same thing more elegantly using one of the provided higher order function such as Seq.exists or Seq.tryfind. However, there are still some cases where the imperative programming style makes it easier to express our original intention. Also, implementing your own higher order functions (akin to Seq.exists) would sometimes be much easier if we could just use imperative return.

So, what can be done about this?

Published: Thursday, 19 March 2009, 2:05 AM
Tags: functional, academic, f#
Read the complete article

Real World Functional Programming: Second review finished!

I've been working on the Real World Functional Programming in .NET book for quite some time now. In fact, I had the first discussions with Michael Stephens from Manning in March last year and I started thinking about the book at that time, so it has been occupying my mind for almost a year now! Until recently, I was feeling that we're not getting much closer to the end of this project, because writing a book is just a lot of work. However, I think I can finally see that we're getting closer to actually finishing the book. At Manning, we've recently finished the second review, which means that I've just got another set of very useful comments - a big thanks to all the reviewers! I'm also getting close to finishing the first draft of the whole manuscript (depending on the reviews, the content may still change a bit, but I expect to write at most one new chapter from now). Hopefully, the drafts will soon make it to the MEAP release of the book.

Published: Monday, 2 March 2009, 12:40 AM
Tags: functional, universe
Read the complete article

All blog posts by tag

f# (112), functional (66), research (49), c# (37), academic (27), asynchronous (27), parallel (23), programming languages (22), functional programming (20), universe (20), meta-programming (18), philosophy (16), links (15), presentations (14), data science (12), writing (12), joinads (12), web (11), thegamma (11), talks (9), data journalism (9), math and numerics (9), random thoughts (9), phalanger (8), haskell (7), mono (7), webcast (7), design (6), architecture (5), fslab (5), open source (5), visualization (4), fun (4), accelerator (4), type providers (3), linq (3), f# data (3), .net (3), training (2), coeffects (2), deedle (2), monads (2), art (2), fractals (2), funscript (2), new york (2), manning (2), books (2)