<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	xmlns:georss="http://www.georss.org/georss" xmlns:geo="http://www.w3.org/2003/01/geo/wgs84_pos#" xmlns:media="http://search.yahoo.com/mrss/"
	>

<channel>
	<title>Higher Order Functions</title>
	<atom:link href="http://higherorderfunctions.wordpress.com/feed/" rel="self" type="application/rss+xml" />
	<link>http://higherorderfunctions.wordpress.com</link>
	<description>Functional Programming using F#</description>
	<lastBuildDate>Sun, 13 Dec 2009 02:55:41 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.com/</generator>
<cloud domain='higherorderfunctions.wordpress.com' port='80' path='/?rsscloud=notify' registerProcedure='' protocol='http-post' />
<image>
		<url>http://s2.wp.com/i/buttonw-com.png</url>
		<title>Higher Order Functions</title>
		<link>http://higherorderfunctions.wordpress.com</link>
	</image>
	<atom:link rel="search" type="application/opensearchdescription+xml" href="http://higherorderfunctions.wordpress.com/osd.xml" title="Higher Order Functions" />
	<atom:link rel='hub' href='http://higherorderfunctions.wordpress.com/?pushpress=hub'/>
		<item>
		<title>Fold and Unfold</title>
		<link>http://higherorderfunctions.wordpress.com/2009/12/12/fold-and-unfold/</link>
		<comments>http://higherorderfunctions.wordpress.com/2009/12/12/fold-and-unfold/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 07:28:12 +0000</pubDate>
		<dc:creator>higherorderfunctions</dc:creator>
				<category><![CDATA[Language]]></category>

		<guid isPermaLink="false">http://higherorderfunctions.wordpress.com/?p=36</guid>
		<description><![CDATA[&#62; Seq.fold;; val it : ((&#8216;a -&#62; &#8216;b -&#62; &#8216;a) -&#62; &#8216;a -&#62; &#8216;b list -&#62; &#8216;a) &#62; Seq.unfold;; val it : ((&#8216;a -&#62; (&#8216;b * &#8216;a) option) -&#62; &#8216;a -&#62; seq&#60;&#8217;b&#62;) The Seq.fold function takes three arguments: 1. A function that takes two arguments, an accumulator and an item from a sequence, and returns [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=higherorderfunctions.wordpress.com&amp;blog=10915682&amp;post=36&amp;subd=higherorderfunctions&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p class="code">
&gt; Seq.fold;;<br />
val it : ((&#8216;a -&gt; &#8216;b -&gt; &#8216;a) -&gt; &#8216;a -&gt; &#8216;b list -&gt; &#8216;a)<br />
&gt; Seq.unfold;;<br />
val it : ((&#8216;a -&gt; (&#8216;b * &#8216;a) option) -&gt; &#8216;a -&gt; seq&lt;&#8217;b&gt;)
</p>
<p>The Seq.fold function takes three arguments:<br />
1. A function that takes two arguments, an accumulator and an item from a sequence, and returns an updated accumulator.<br />
2. The initial value for the accumulator.<br />
3. A sequence of items.<br />
Returns:  A single, aggregated value.</p>
<p>The Seq.unfold function takes two arguments:<br />
1. A function that takes one arguments, an accumulator, and returns a tuple, consisting of a value to be inserted into the sequence and an updated accumulator.<br />
2. The initial value for the accumulator.<br />
Returns: A new sequence of values generated from the function (1) above.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/higherorderfunctions.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/higherorderfunctions.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/higherorderfunctions.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/higherorderfunctions.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/higherorderfunctions.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/higherorderfunctions.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/higherorderfunctions.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/higherorderfunctions.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/higherorderfunctions.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/higherorderfunctions.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/higherorderfunctions.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/higherorderfunctions.wordpress.com/36/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/higherorderfunctions.wordpress.com/36/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/higherorderfunctions.wordpress.com/36/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=higherorderfunctions.wordpress.com&amp;blog=10915682&amp;post=36&amp;subd=higherorderfunctions&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://higherorderfunctions.wordpress.com/2009/12/12/fold-and-unfold/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e748a3f92509dfa008da26183f8e386e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">higherorderfunctions</media:title>
		</media:content>
	</item>
		<item>
		<title>Project Euler : Q3</title>
		<link>http://higherorderfunctions.wordpress.com/2009/12/12/project-euler-q3/</link>
		<comments>http://higherorderfunctions.wordpress.com/2009/12/12/project-euler-q3/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 04:48:24 +0000</pubDate>
		<dc:creator>higherorderfunctions</dc:creator>
				<category><![CDATA[Project Euler]]></category>

		<guid isPermaLink="false">http://higherorderfunctions.wordpress.com/2009/12/12/project-euler-q3/</guid>
		<description><![CDATA[What is the largest prime factor of the number 600851475143 ? let the_num = 600851475143L;; let isFactor (numerator : int64) (denominator : int64) = (numerator % denominator = 0L);; let get_factors (n : int64) = List.sort [for x in 1L .. int64(ceil(sqrt(float n))) do if ((isFactor n x) &#38;&#38; (x &#60;&#62; 1L)) then yield x; [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=higherorderfunctions.wordpress.com&amp;blog=10915682&amp;post=30&amp;subd=higherorderfunctions&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>What is the largest prime factor of the number 600851475143 ?</p>
<p class="code">let the_num = 600851475143L;;<br />
let isFactor (numerator : int64) (denominator : int64) = (numerator % denominator = 0L);;<br />
let get_factors (n : int64) = List.sort [for x in 1L .. int64(ceil(sqrt(float n))) do if ((isFactor n x) &amp;&amp; (x &lt;&gt; 1L)) then yield x; yield (n / x)];;<br />
let isPrime (n : int64) = (List.length (get_factors n)) = 0;;<br />
let the_factors = the_num |&gt; get_factors |&gt; List.rev;;<br />
let prime, notprime = List.partition isPrime the_factors;;<br />
List.head prime;;</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/higherorderfunctions.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/higherorderfunctions.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/higherorderfunctions.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/higherorderfunctions.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/higherorderfunctions.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/higherorderfunctions.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/higherorderfunctions.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/higherorderfunctions.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/higherorderfunctions.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/higherorderfunctions.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/higherorderfunctions.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/higherorderfunctions.wordpress.com/30/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/higherorderfunctions.wordpress.com/30/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/higherorderfunctions.wordpress.com/30/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=higherorderfunctions.wordpress.com&amp;blog=10915682&amp;post=30&amp;subd=higherorderfunctions&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://higherorderfunctions.wordpress.com/2009/12/12/project-euler-q3/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e748a3f92509dfa008da26183f8e386e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">higherorderfunctions</media:title>
		</media:content>
	</item>
		<item>
		<title>Project Euler : Q2</title>
		<link>http://higherorderfunctions.wordpress.com/2009/12/12/project-euler-q2/</link>
		<comments>http://higherorderfunctions.wordpress.com/2009/12/12/project-euler-q2/#comments</comments>
		<pubDate>Sat, 12 Dec 2009 00:27:07 +0000</pubDate>
		<dc:creator>higherorderfunctions</dc:creator>
				<category><![CDATA[Project Euler]]></category>

		<guid isPermaLink="false">http://higherorderfunctions.wordpress.com/?p=26</guid>
		<description><![CDATA[Find the sum of all the even-valued terms in the sequence of Fibonacci numbers. Do not include Fibonacci numbers greater than 4,000,000. let fibs = (1,2) &#124;&#62; Seq.unfold (fun (a,b) -&#62; if a &#60; 4000000 then Some(a, (b, a+b)) else None);; let sum acc itm = if (itm % 2 = 0) then acc + [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=higherorderfunctions.wordpress.com&amp;blog=10915682&amp;post=26&amp;subd=higherorderfunctions&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Find the sum of all the even-valued terms in the sequence of Fibonacci numbers.  Do not include Fibonacci numbers greater than 4,000,000.</p>
<p class="code">
let fibs = (1,2) |&gt; Seq.unfold (fun (a,b) -&gt; if a &lt; 4000000 then Some(a, (b, a+b)) else None);;<br />
let sum acc itm = if (itm % 2 = 0) then acc + itm else acc;;<br />
let answer = List.fold sum 0 (Seq.toList fibs);;
</p>
<p>In this problem, I need to gather all the Fibonacci numbers that do not exceed four-million, then filter out the odd ones and sum the result.</p>
<p>First, I generate a sequence of Fibonacci numbers using the Seq.unfold function.  It has two parameters:  A function which will calculate the next value in the sequence, and the initial value supplied to that function.  The function has a return type of option.  This is why the Some/None keywords are used.  If a value is present we use Some(value), else None which is like null.  Once a None or null is encountered, the sequence will end.  In the Some function, it returns a tuple.  The first part of the tuple is what will go into the sequence, the second part is the updated values being fed back into the function.  Notice that I said that the Seq.unfold function has two parameters, but only one argument is being passed in, so where is the other argument?  Well, it actually is specified before the function call.  The tuple (1,2) is followed by the pipe-forward operator.  This takes that tuple and supplies it to the last parameter of the function that it proceeds, in this case, the Seq.unfold function.</p>
<p>Second, I create a summation function.  It takes an accumulator and the next item in a list.  As each item runs through the function, the accumulator gets larger and larger, but only if the item in question is even.  If the item is odd, then the accumulator remains unchanged.</p>
<p>Finally, all of the pieces get put together.  I use the List.fold function, passing in the summation function, the initial value of the accumulator, and the list of Fibonacci numbers less than four million.  All of the values in the list have been folded or aggregated into a single value: the sum.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/higherorderfunctions.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/higherorderfunctions.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/higherorderfunctions.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/higherorderfunctions.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/higherorderfunctions.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/higherorderfunctions.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/higherorderfunctions.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/higherorderfunctions.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/higherorderfunctions.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/higherorderfunctions.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/higherorderfunctions.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/higherorderfunctions.wordpress.com/26/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/higherorderfunctions.wordpress.com/26/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/higherorderfunctions.wordpress.com/26/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=higherorderfunctions.wordpress.com&amp;blog=10915682&amp;post=26&amp;subd=higherorderfunctions&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://higherorderfunctions.wordpress.com/2009/12/12/project-euler-q2/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e748a3f92509dfa008da26183f8e386e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">higherorderfunctions</media:title>
		</media:content>
	</item>
		<item>
		<title>Project Euler : Q1</title>
		<link>http://higherorderfunctions.wordpress.com/2009/12/11/project-euler-q1/</link>
		<comments>http://higherorderfunctions.wordpress.com/2009/12/11/project-euler-q1/#comments</comments>
		<pubDate>Fri, 11 Dec 2009 22:19:14 +0000</pubDate>
		<dc:creator>higherorderfunctions</dc:creator>
				<category><![CDATA[Project Euler]]></category>

		<guid isPermaLink="false">http://higherorderfunctions.wordpress.com/?p=3</guid>
		<description><![CDATA[Sum up all the numbers, less than 1000, that are divisible by 3 or 5. List.fold (fun acc itm -&#62; acc + itm) 0 [for x in 1..999 do if (x % 3 = 0) &#124;&#124; (x % 5 = 0) then yield x];; The List.fold function takes three arguments: 1. A function. This function [...]<img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=higherorderfunctions.wordpress.com&amp;blog=10915682&amp;post=3&amp;subd=higherorderfunctions&amp;ref=&amp;feed=1" width="1" height="1" />]]></description>
			<content:encoded><![CDATA[<p>Sum up all the numbers, less than 1000, that are divisible by 3 or 5.</p>
<p class="code">
List.fold (fun acc itm -&gt; acc + itm) 0 [for x in 1..999 do if (x % 3 = 0) || (x % 5 = 0) then yield x];;
</p>
<p>The List.fold function takes three arguments:<br />
1.  A function.  This function takes two arguments, the first is an accumulator or the aggregated value, the second argument is an item being supplied from a list.<br />
2.  The accumulator&#8217;s (see above) starting value.<br />
3.  A list.</p>
<p>In the above code, I&#8217;m creating a list using list comprehension syntax.  It is iterating from 1 to 999 and checks if each number is divisible by either 3 or 5.  If it is, then it gets added to the list.  After the list gets created, it gets fed into the lambda function (anonymous).  The 0, zero, is the starting value for the accumulator.  As each number in the list gets fed to the lambda the total value gets larger and larger until the list has exhausted all the values.  The fold function then terminates, returning the accumulator, which in this case is the sum of all the numbers 1 to 999 that are factors of either 3 or 5.</p>
<br />  <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gocomments/higherorderfunctions.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/comments/higherorderfunctions.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godelicious/higherorderfunctions.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/delicious/higherorderfunctions.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gofacebook/higherorderfunctions.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/facebook/higherorderfunctions.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gotwitter/higherorderfunctions.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/twitter/higherorderfunctions.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/gostumble/higherorderfunctions.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/stumble/higherorderfunctions.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/godigg/higherorderfunctions.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/digg/higherorderfunctions.wordpress.com/3/" /></a> <a rel="nofollow" href="http://feeds.wordpress.com/1.0/goreddit/higherorderfunctions.wordpress.com/3/"><img alt="" border="0" src="http://feeds.wordpress.com/1.0/reddit/higherorderfunctions.wordpress.com/3/" /></a> <img alt="" border="0" src="http://stats.wordpress.com/b.gif?host=higherorderfunctions.wordpress.com&amp;blog=10915682&amp;post=3&amp;subd=higherorderfunctions&amp;ref=&amp;feed=1" width="1" height="1" />]]></content:encoded>
			<wfw:commentRss>http://higherorderfunctions.wordpress.com/2009/12/11/project-euler-q1/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
	
		<media:content url="http://0.gravatar.com/avatar/e748a3f92509dfa008da26183f8e386e?s=96&#38;d=identicon&#38;r=G" medium="image">
			<media:title type="html">higherorderfunctions</media:title>
		</media:content>
	</item>
	</channel>
</rss>
