<?xml version="1.0" encoding="UTF-8" ?>
<?xml-stylesheet type="text/xsl" href="http://blogs.msdn.com/utility/FeedStylesheets/rss.xsl" media="screen"?><rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:wfw="http://wellformedweb.org/CommentAPI/"><channel><title>WideFinder--Naive F# Implementation</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/10/22/widefinder-naive-f-implementation.aspx</link><description>Jomo Fisher--Here's an interesting problem that some people are having fun with. Don Box posted a naive implementation in C# so I thought I'd post the equivalent in F#: #light open System.Text.RegularExpressions open System.IO open System.Text let regex</description><dc:language>en-US</dc:language><generator>CommunityServer 2.1 SP1 (Build: 61025.2)</generator><item><title>Scott Hanselman's Computer Zen - The Weekly Source Code 9 - WideFinder Edition</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/10/22/widefinder-naive-f-implementation.aspx#5617009</link><pubDate>Tue, 23 Oct 2007 08:24:24 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5617009</guid><dc:creator>Scott Hanselman's Computer Zen - The Weekly Source Code 9 - WideFinder Edition</dc:creator><description>&lt;p&gt;PingBack from &lt;a rel="nofollow" target="_new" href="http://www.hanselman.com/blog/TheWeeklySourceCode9WideFinderEdition.aspx"&gt;http://www.hanselman.com/blog/TheWeeklySourceCode9WideFinderEdition.aspx&lt;/a&gt;&lt;/p&gt;
</description></item><item><title>The Weekly Source Code 9 - WideFinder Edition</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/10/22/widefinder-naive-f-implementation.aspx#5617327</link><pubDate>Tue, 23 Oct 2007 08:45:15 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5617327</guid><dc:creator>ASPInsiders</dc:creator><description>&lt;p&gt;In my new ongoing quest to read source code to be a better developer , I now present the ninth in an&lt;/p&gt;
</description></item><item><title>re: WideFinder--Naive F# Implementation</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/10/22/widefinder-naive-f-implementation.aspx#5629048</link><pubDate>Tue, 23 Oct 2007 20:58:09 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:5629048</guid><dc:creator>JHugard</dc:creator><description>&lt;p&gt;Don't forget to add &amp;quot;take the top 10&amp;quot; and &amp;quot;print to stdout&amp;quot;:&lt;/p&gt;
&lt;p&gt;#light&lt;/p&gt;
&lt;p&gt;open System.Text.RegularExpressions&lt;/p&gt;
&lt;p&gt;open System.IO&lt;/p&gt;
&lt;p&gt;open System.Text&lt;/p&gt;
&lt;p&gt;let regex = new Regex(@&amp;quot;GET /ongoing/When/\d\d\dx/(\d\d\d\d/\d\d/\d\d/[^ .]+)&amp;quot;, RegexOptions.Compiled)&lt;/p&gt;
&lt;p&gt;let seqRead fileName =&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;seq { use reader = new StreamReader(File.OpenRead(fileName))&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;while not reader.EndOfStream do&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp; &amp;nbsp;yield reader.ReadLine() }&lt;/p&gt;
&lt;p&gt;let query fileName = &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;seqRead fileName&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;|&amp;gt; Seq.map (fun line -&amp;gt; regex.Match(line)) &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;|&amp;gt; Seq.filter (fun regMatch -&amp;gt; regMatch.Success)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;|&amp;gt; Seq.map (fun regMatch -&amp;gt; regMatch.Value)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;|&amp;gt; Seq.countBy (fun url -&amp;gt; url)&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;|&amp;gt; Seq.take 10&lt;/p&gt;
&lt;p&gt;for result in query @&amp;quot;file.txt&amp;quot; do &lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;let url, count = result&lt;/p&gt;
&lt;p&gt; &amp;nbsp; &amp;nbsp;printfn &amp;quot;%A - %A&amp;quot; url count&lt;/p&gt;</description></item><item><title>re: WideFinder--Naive F# Implementation</title><link>http://blogs.msdn.com/jomo_fisher/archive/2007/10/22/widefinder-naive-f-implementation.aspx#6688728</link><pubDate>Fri, 07 Dec 2007 07:33:44 GMT</pubDate><guid isPermaLink="false">91d46819-8472-40ad-a661-2c78acb4018c:6688728</guid><dc:creator>Tony Nassar</dc:creator><description>&lt;P&gt;I enjoy your blog, and it's helped inspire me to learn F#. Since it's hard to introduce it into production code (my colleagues, and the build machine, would have to have F# installed), I'm using it for one-off scripts. Wow, it's strange to be using a REPL again! Anyway, I have to munge through text files, and would recommend Seq.generate_using for that purpose:&lt;/P&gt;
&lt;P&gt;let lines = Seq.generate_using (fun () -&amp;gt; File.OpenText(@"solveBatch.Cplex.txt")) &lt;/P&gt;
&lt;P&gt;(fun (stream : StreamReader) -&amp;gt; match stream.ReadLine() with | null -&amp;gt; None | line -&amp;gt; Some line);;&lt;/P&gt;
&lt;P&gt;That took me about 30 minutes to get right. It would have been faster to cut and paste, but in the end I learned something.&lt;/P&gt;</description></item></channel></rss>