<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/"><channel><title>Functional-Programming on Dr. Random</title><link>https://drrandom.org/tags/functional-programming/</link><description>Recent content in Functional-Programming on Dr. Random</description><generator>Hugo</generator><language>en-gb</language><lastBuildDate>Sun, 14 Jun 2015 21:09:13 +0000</lastBuildDate><atom:link href="https://drrandom.org/tags/functional-programming/index.xml" rel="self" type="application/rss+xml"/><item><title>A bit on making functions tail-recursive in F#</title><link>https://drrandom.org/2015/06/14/a-bit-on-making-functions-tail-recursive-in-f/</link><pubDate>Sun, 14 Jun 2015 21:09:13 +0000</pubDate><guid>https://drrandom.org/2015/06/14/a-bit-on-making-functions-tail-recursive-in-f/</guid><description>&lt;p&gt;If you recall a while back when I was &lt;a href="https://drrandom.org/2012/07/24/purely-functional-data-structures-part-2/"&gt;demonstrating some Functional Data Structures&lt;/a&gt;, I mentioned the fact that some of the functions were not tail recursive, and that this is something that we would probably want to do something about. Which raises the question: How exactly do we go about making a function tail-recursive? I am going to attempt to address that question here.&lt;/p&gt;
&lt;p&gt;One of the first problems with creating a tail recursive function is figuring out whether a function is tail recursive in the first place. Sadly this isn’t something that is always obvious. There has been some discussion about generating a compiler warning if a function is not tail recursive, which sounds like a dandy idea since the compiler knows enough to know how to optimize tail recursive functions for us. But we don’t have that yet, so we’re going to have to try and figure it out on our own. So here are some things to look for:&lt;/p&gt;</description></item><item><title>fold - The greatest thing that ever happened to your data structure</title><link>https://drrandom.org/2015/06/08/foldthe-greatest-thing-that-ever-happened-to-your-data-structure/</link><pubDate>Mon, 08 Jun 2015 17:16:22 +0000</pubDate><guid>https://drrandom.org/2015/06/08/foldthe-greatest-thing-that-ever-happened-to-your-data-structure/</guid><description>&lt;p&gt;Let&amp;rsquo;s say that you’ve been working hard on this really awesome data structure. Its fast, its space efficient, its immutable, its everything anyone could dream of in a data structure. But you only have time to implement one function for processing the data in your new miracle structure, so what would it be?&lt;/p&gt;
&lt;p&gt;Ok, not a terribly realistic scenario, but bare with me here, there is a point to this. The answer to this question, of course, is that you would implement &lt;code&gt;fold&lt;/code&gt;. Why you might ask? Because if you have a fold implementation then it is possible to implement just about any other function you want in terms of fold. Don’t believe me? Well, I’ll show you, and in showing you I’ll also demonstrate how finding the right abstraction in a functional language can reduce the size and complexity of your codebase in amazing ways.&lt;/p&gt;</description></item><item><title>Purely Functional Data Structures–Part 2</title><link>https://drrandom.org/2012/07/24/purely-functional-data-structures-part-2/</link><pubDate>Tue, 24 Jul 2012 18:15:17 +0000</pubDate><guid>https://drrandom.org/2012/07/24/purely-functional-data-structures-part-2/</guid><description>&lt;p&gt;So here we are at part 2 in the series of posts looking at Functional Data Structures from the book of the same name by Chris Okasaki. &lt;a href="https://drrandom.org/2012/07/23/purely-functional-data-structures-part-1/"&gt;Last time&lt;/a&gt; we looked at what is perhaps the simplest of the functional data structures, the List (also useful as a LIFO stack).  Up next we’ll continue in the order that Chris Okasaki used in his book, and take a look at implementing a Set using a Binary Tree.&lt;/p&gt;</description></item><item><title>Purely Functional Data Structures–Part 1</title><link>https://drrandom.org/2012/07/23/purely-functional-data-structures-part-1/</link><pubDate>Mon, 23 Jul 2012 06:00:00 +0000</pubDate><guid>https://drrandom.org/2012/07/23/purely-functional-data-structures-part-1/</guid><description>&lt;p&gt;I thought it might be fun to explore a little bit of CS as it applies to functional programming, by looking at the idea of Functional Data Structures.  This is actually an area that is still getting a lot of active research, and is pretty interesting stuff overall.  The general idea is to try and figure out ways to provide immutable data structures which can be efficiently implemented in a functional setting.  So you look at some standard data structures, like a linked list, and find a way to implement that as an immutable linked list.  One of the really cool features of Functional Data Structures is that because your dealing with them in an immutable setting, you can actually get a lot of re-use out of them….specifically for something like a list, you can add an item to the list, and return a “new” list that consists of the old list and the new item, and literally provide a structure that points to the old list instead of copying items.  Even if you have other parts of the code referencing older versions of the list without the new item, you don’t have to worry since none of them can mutate the list.&lt;/p&gt;</description></item><item><title>A quick (?) retrospective on learning (and using) F#</title><link>https://drrandom.org/2012/07/22/a-quick-retrospective-on-learning-and-using-f/</link><pubDate>Sun, 22 Jul 2012 15:00:00 +0000</pubDate><guid>https://drrandom.org/2012/07/22/a-quick-retrospective-on-learning-and-using-f/</guid><description>&lt;p&gt;As you may have guessed from the title, I’ve started doing some work with F#.  Initially I was somewhat reluctant to go down the F# path because some of the more interesting aspects of the other functional languages I’ve been exploring are not present…specifically the type systems behind Scala and Haskell, the laziness of Haskell, and the concurrent programming model of Erlang.  In spite of these perceived downfalls, there were some definite plusses, namely interoperability with everything .Net, immutability by default, and the wonderful concise programing model of a functional language.&lt;/p&gt;</description></item><item><title>I think Scala may be a gateway drug</title><link>https://drrandom.org/2012/01/24/i-think-scala-may-be-a-gateway-drug/</link><pubDate>Tue, 24 Jan 2012 06:52:00 +0000</pubDate><guid>https://drrandom.org/2012/01/24/i-think-scala-may-be-a-gateway-drug/</guid><description>&lt;p&gt;As I have been trying to learn more about Scala, there have been several paths that I’ve had to follow.  One is getting acquainted with the state of Java development, since ultimately Scala exists within the Java ecosystem.  Another is finding my way around the Scala libraries, tools, and idioms.  But there is a third that seems to be somewhat deeper, and that is coming to grips with the functional nature of the language.&lt;/p&gt;</description></item><item><title>Making the Climb Part 4–Pattern Matching</title><link>https://drrandom.org/2012/01/22/making-the-climb-part-4-pattern-matching/</link><pubDate>Sun, 22 Jan 2012 20:23:58 +0000</pubDate><guid>https://drrandom.org/2012/01/22/making-the-climb-part-4-pattern-matching/</guid><description>&lt;p&gt;Continuing our journey down the path from the familiar to the down-right bizarre, we find ourselves at Pattern Matching.  This is a feature of the Scala language that shows it’s functional side in a strong way.  Pattern Matching is a fundamental part of functional languages in general, and provides a way to write very concise and expressive code.  On the surface, pattern matching in Scala looks an awful lot like switch statements in C# (and Java for that matter), but you shouldn’t cling too hard to that association.&lt;/p&gt;</description></item></channel></rss>