<rss version="2.0" xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:trackback="http://madskills.com/public/xml/rss/module/trackback/" xmlns:wfw="http://wellformedweb.org/CommentAPI/" xmlns:slash="http://purl.org/rss/1.0/modules/slash/" xmlns:copyright="http://blogs.law.harvard.edu/tech/rss" xmlns:image="http://purl.org/rss/1.0/modules/image/">
    <channel>
        <title>Functional Programming</title>
        <link>http://geekswithblogs.net/nickholmes/category/10041.aspx</link>
        <description>Functional Programming</description>
        <language>en-GB</language>
        <copyright>Nick Holmes</copyright>
        <managingEditor>nickh@coyote-software.com</managingEditor>
        <generator>Subtext Version 0.0.0.0</generator>
        <item>
            <title>Problems with WCF Data Contracts in F#</title>
            <link>http://geekswithblogs.net/nickholmes/archive/2009/05/06/problems-with-wcf-data-contracts-in-f.aspx</link>
            <description>&lt;p&gt;[Update: This blog post was orignally posted in early 2008, in another blog. Things have changed a little in F#, and Ted Nedward has provided updated information related to this, showing &lt;a href="http://blogs.tedneward.com/2009/01/24/Building+WCF+Services+With+F+Part+2.aspx"&gt;how to create data contracts in F#&lt;/a&gt;]&lt;/p&gt;
&lt;p&gt;On the road to a really interesting Web Service, I increased the complexity of my "could-not-be-simpler" web service one notch, and added a class-typed argument to the operation. This requires constructing of a Data Contract, so that WCF can build the correct WSDL, and also know how to serialize (and de-serialize) messages. As with the Service Contract, this is simply done with a couple of attributes, like this:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;&lt;strong&gt;[&amp;lt;DataContract&amp;gt;]&lt;/strong&gt; &lt;br /&gt;
type public SimpleDataContract() = &lt;br /&gt;
        let mutable _propertyOne = System.String.Empty &lt;br /&gt;
        let mutable _propetyTwo = 0 &lt;br /&gt;
        &lt;strong&gt;[&amp;lt;DataMember&amp;gt;]&lt;/strong&gt; &lt;br /&gt;
        member public x.PropertyOne &lt;br /&gt;
            with get() = _propertyOne &lt;br /&gt;
            and set(value) = _propertyOne &amp;lt;- value            &lt;br /&gt;
        &lt;strong&gt;[&amp;lt;DataMember&amp;gt;]&lt;/strong&gt; &lt;br /&gt;
        member public x.PropertyTwo &lt;br /&gt;
            with get() = _propetyTwo &lt;br /&gt;
            and set(value) = _propetyTwo &amp;lt;- value&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;[&amp;lt;ServiceContract(ConfigurationName = "ISimpleService", Namespace = "&lt;a href="http://coyote-software.com/FSWCF/SimpleService"&gt;http://coyote-software.com/FSWCF/SimpleService")&lt;/a&gt;&amp;gt;] &lt;br /&gt;
type ISimpleService = &lt;br /&gt;
    [&amp;lt;OperationContract&amp;gt;] &lt;br /&gt;
    abstract TestMethod: Param:SimpleDataContract -&amp;gt; string&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;&lt;code&gt;[&amp;lt;ServiceBehavior(InstanceContextMode = InstanceContextMode.PerSession)&amp;gt;] &lt;br /&gt;
type SimpleService() = &lt;br /&gt;
    interface ISimpleService with &lt;br /&gt;
        member x.TestMethod s = "Hello " + s.PropertyOne;&lt;/code&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;Unfortunately, code causes a run-time exception when the service is started (well before any messages arrive). The error is about "method get_PropertyOne" not being a property, and therefore an invalid recipient of the DataMember attribute. I strongly suspect that this is due to a know bug in the current F# compiler emitting IL for properties in a non-standard way.&lt;/p&gt;
&lt;p&gt;(WCF data contract members must be placed on properties, and not fields.)&lt;/p&gt;
&lt;p&gt;The obvious work-around is to create the class in C#. The equivalent C# class is simply:&lt;/p&gt;
&lt;blockquote&gt;
&lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;    [DataContract] &lt;br /&gt;
    public class SimpleDataContract &lt;br /&gt;
    { &lt;br /&gt;
        public SimpleDataContract() { }&lt;/code&gt;&lt;code&gt;&lt;br /&gt;
        [DataMember] &lt;br /&gt;
        public string PropertyOne { get; set; } &lt;br /&gt;
        [DataMember] &lt;br /&gt;
        public int PropertyTwo { get; set; } &lt;br /&gt;
    }&lt;/code&gt; &lt;/p&gt;
&lt;p&gt;  &lt;/p&gt;
&lt;/blockquote&gt;
&lt;p&gt;For once, C# trumps F# for brevity! Anyway, using this class from F# is no more complex than referencing the dll, and removing the F# SimpleDataContract class, and the web service now works as expected.&lt;/p&gt;
&lt;p&gt;The next step is to do something a little more interesting in the operation; use LINQ to SQL to query a database, and return some data. As it turns out, our data contracts will be again come via C#, so this issue will be by-passed.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131844"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131844" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/nickholmes/aggbug/131844.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Nick Holmes</dc:creator>
            <guid>http://geekswithblogs.net/nickholmes/archive/2009/05/06/problems-with-wcf-data-contracts-in-f.aspx</guid>
            <pubDate>Wed, 06 May 2009 20:09:32 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/nickholmes/comments/131844.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/nickholmes/archive/2009/05/06/problems-with-wcf-data-contracts-in-f.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/nickholmes/comments/commentRss/131844.aspx</wfw:commentRss>
        </item>
        <item>
            <title>An WCF Service Host in F#</title>
            <link>http://geekswithblogs.net/nickholmes/archive/2009/05/05/an-wcf-service-host-in-f.aspx</link>
            <description>&lt;p&gt;I had half an hour to fill while I waited for a large download, on my slow connection. I'd thought about re-implementing my C# WCF test host in F#. It didn't look too complex, and indeed it wasn't:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;#light      &lt;br /&gt;#I @"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\"       &lt;br /&gt;#r "System.ServiceModel.dll"       &lt;br /&gt;#r "Server.dll"       &lt;br /&gt;open System       &lt;br /&gt;open System.ServiceModel       &lt;br /&gt;open System.Diagnostics       &lt;br /&gt;open Coyote.FSWCFTest&lt;/code&gt;&lt;/p&gt;  &lt;p align="left"&gt;&lt;code&gt;let services =&lt;/code&gt;&lt;/p&gt;  &lt;p align="left"&gt;&lt;code&gt;    [ (typeof&amp;lt;TestWebService&amp;gt;, "http://localhost:8080/Test/FSWCFTest.svc") ]&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;&lt;code&gt;let logException (msg, exn:Exception) =      &lt;br /&gt;    Trace.TraceWarning(msg)       &lt;br /&gt;    Trace.WriteLine(exn.Message)       &lt;br /&gt;    Trace.WriteLine(exn.Source)&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;let startHost (serviceType:Type, url) =      &lt;br /&gt;    try       &lt;br /&gt;        let uri = [| new Uri(url) |]       &lt;br /&gt;        let host = new ServiceHost(serviceType, uri)       &lt;br /&gt;        host.Open()       &lt;br /&gt;        Some(host)       &lt;br /&gt;    with       &lt;br /&gt;    | e -&amp;gt; logException ("Exception thrown starting service.", e)       &lt;br /&gt;           None&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;&lt;code&gt;&lt;/code&gt;&lt;code&gt;let stop&lt;/code&gt;&lt;code&gt;Host (host: ServiceHost option)  =      &lt;br /&gt;    try       &lt;br /&gt;        match host with       &lt;br /&gt;        | None -&amp;gt; ()       &lt;br /&gt;        | Some(host) -&amp;gt;       &lt;br /&gt;            if host.State &amp;lt;&amp;gt; CommunicationState.Closed then       &lt;br /&gt;                host.Close()       &lt;br /&gt;                Trace.WriteLine("Service Stopped")                &lt;br /&gt;    with       &lt;br /&gt;    | e -&amp;gt; logException ("Exception thrown stopping service.", e)&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;&lt;code&gt;let showHostStatus (host: ServiceHost option) =      &lt;br /&gt;    match host with       &lt;br /&gt;    | Some(hst) -&amp;gt;       &lt;br /&gt;        let strdots = new String ( '.', 40 - hst.Description.Name.Length);       &lt;br /&gt;        Console.ForegroundColor &amp;lt;- match hst.State with       &lt;br /&gt;                                   | CommunicationState.Opened -&amp;gt; ConsoleColor.Green       &lt;br /&gt;                                   | _ -&amp;gt; ConsoleColor.Red         &lt;br /&gt;        Console.WriteLine("{0} service{1}{2}", hst.Description.Name,&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;&lt;code&gt;            strdots, hst.State.ToString())      &lt;br /&gt;    | None -&amp;gt; Console.ForegroundColor &amp;lt;- ConsoleColor.Red       &lt;br /&gt;              Console.WriteLine("Service failed to start.")&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;&lt;code&gt;let main =      &lt;br /&gt;    Console.Title &amp;lt;- "Server Test Console"       &lt;br /&gt;    Console.BackgroundColor &amp;lt;- ConsoleColor.DarkBlue       &lt;br /&gt;    Console.WindowWidth &amp;lt;- 120       &lt;br /&gt;    Console.Clear()       &lt;br /&gt;    Console.WriteLine("Server Test Console")       &lt;br /&gt;    Console.WriteLine("Copyright 2008 Coyote Software, GmbH.")       &lt;br /&gt;    Console.WriteLine()       &lt;br /&gt;    let hosts = services |&amp;gt; List.map startHost       &lt;br /&gt;    let mutable quit = false       &lt;br /&gt;    while not quit do       &lt;br /&gt;        let inp = Console.ReadLine()   &lt;br /&gt;        let inpClean = inp.Trim().ToLower()       &lt;br /&gt;        match inpClean with       &lt;br /&gt;        | "exit"   -&amp;gt; quit &amp;lt;- true       &lt;br /&gt;        | "cls"    -&amp;gt; Console.Clear()       &lt;br /&gt;        | "status" -&amp;gt; let cc = Console.ForegroundColor       &lt;br /&gt;                      Console.WriteLine("Status at {0} is", DateTime.Now)       &lt;br /&gt;                      hosts |&amp;gt; List.iter showHostStatus       &lt;br /&gt;                      Console.ForegroundColor &amp;lt;- cc       &lt;br /&gt;        | "stop"   -&amp;gt; hosts |&amp;gt; List.iter stopHost       &lt;br /&gt;        | _        -&amp;gt; Console.WriteLine("Unknown command {0}", inp)       &lt;br /&gt;    done&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;This implementation is about half the size of the C# implementation, although the original has a couple of extra commands. I preferred Console.WriteLine to printfn, as I have used other Console methods, and I think the code is a little clearer.&lt;/p&gt;  &lt;p&gt;One improvement to this app would be to have is use reflection to automatically find all  the services in the assembly (rather than require the list to be set up), but I've been using the C# version almost daily for over a year, and its good enough like this.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131814"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131814" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/nickholmes/aggbug/131814.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Nick Holmes</dc:creator>
            <guid>http://geekswithblogs.net/nickholmes/archive/2009/05/05/an-wcf-service-host-in-f.aspx</guid>
            <pubDate>Tue, 05 May 2009 17:50:39 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/nickholmes/comments/131814.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/nickholmes/archive/2009/05/05/an-wcf-service-host-in-f.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/nickholmes/comments/commentRss/131814.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Accessing F# Interface Implementations from C#</title>
            <link>http://geekswithblogs.net/nickholmes/archive/2009/05/05/accessing-f-interface-implementations-from-c.aspx</link>
            <description>&lt;p&gt;I tidied up the F# web service, mainly by factoring out an interface for the web service. Without the attributes it looks like this:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;type ITestWebService =      &lt;br /&gt;    abstract TestMethod: Param:string -&amp;gt; string &lt;/code&gt;&lt;code&gt;type TestWebService() =      &lt;br /&gt;    interface ITestWebService with       &lt;br /&gt;        member x.TestMethod s = "Hello " + s;&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;However, I noticed when I was setting up the C# host, I needed to cast to get to access the interface, like this:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;TestWebService tws = new TestWebService();      &lt;br /&gt;ITestWebService itws = tws as ITestWebService;&lt;/code&gt;&lt;/p&gt;  &lt;p&gt;Neither of these far more obvious ways to access the member work:&lt;/p&gt;  &lt;p&gt;&lt;code&gt;tws.TestMethod("test");                     // Doesn't compile      &lt;br /&gt;tws.ITestWebService.TestMethod("test");     // Doesn't compile &lt;/code&gt;&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131813"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131813" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/nickholmes/aggbug/131813.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Nick Holmes</dc:creator>
            <guid>http://geekswithblogs.net/nickholmes/archive/2009/05/05/accessing-f-interface-implementations-from-c.aspx</guid>
            <pubDate>Tue, 05 May 2009 17:44:12 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/nickholmes/comments/131813.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/nickholmes/archive/2009/05/05/accessing-f-interface-implementations-from-c.aspx#feedback</comments>
            <slash:comments>1</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/nickholmes/comments/commentRss/131813.aspx</wfw:commentRss>
        </item>
        <item>
            <title>An F# WCF Web Service</title>
            <link>http://geekswithblogs.net/nickholmes/archive/2009/05/05/an-f-wcf-web-service.aspx</link>
            <description>&lt;p&gt;For all the power and flexibility that WCF provides, creating a basic web service in C# is easy enough. Essentially, it's just a POCO adorned with some special attributes. Doing the same thing in F#, then, should also be easy enough. I tried this:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;code&gt;#light        &lt;br /&gt;#I @"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\"         &lt;br /&gt;#r "System.ServiceModel.dll"&lt;/code&gt;&lt;/p&gt;    &lt;p&gt;&lt;code&gt;open System.ServiceModel        &lt;br /&gt;&lt;/code&gt;&lt;/p&gt;    &lt;p&gt;&lt;code&gt;[&amp;lt;ServiceContract(ConfigurationName = "TestWebService", Namespace = "&lt;a href="http://coyote-software.com/FSWCFTest"&gt;http://coyote-software.com/FSWCFTest")&lt;/a&gt;&amp;gt;]         &lt;br /&gt;[&amp;lt;ServiceBehavior(InstanceContextMode=InstanceContextMode.PerCall)&amp;gt;]         &lt;br /&gt;&lt;/code&gt;&lt;code&gt;type public TestWebService =        &lt;br /&gt;    class&lt;/code&gt;&lt;code&gt;        &lt;br /&gt;        [&amp;lt;OperationContract&amp;gt;]         &lt;br /&gt;        member public x.TestMethod(s) = "Hello " + s;         &lt;br /&gt;    end&lt;/code&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Essentially, I've referenced the WCF assembly, and created a class with a single method, and added the needed ServiceContract, ServiceBehavior and OperationContract attributes. I compiled this into to a dll.&lt;/p&gt;  &lt;p&gt;To test this, I needed to host it somewhere. I already have a console host application in C#, and so I used that for testing, and got this exception:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;em&gt;The service type provided could not be loaded as a service because it does not have a default (parameter-less) constructor.&lt;/em&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Constructors in F# are a little different to C#, and a bit of hunting through the spec, and I had my solution:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;code&gt;type public TestWebService&lt;strong&gt;()&lt;/strong&gt; =&lt;/code&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Just a pair of missing parenthesis! This was going extremely well, so the next task is to call the method. For this we need to generate a client proxy with svcutil.exe. This generates C# code, but no reason not to use this, driven from an F# client. I compiled up the generated C# into a dll, and then referenced that from a simple F# console client:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;code&gt;#light        &lt;br /&gt;#I @"C:\Program Files\Reference Assemblies\Microsoft\Framework\v3.0\"         &lt;br /&gt;#I @"c:\Development Projects\Research\FSWCF\Client\bin\debug\"         &lt;br /&gt;#r "System.ServiceModel.dll"         &lt;br /&gt;#r "client.dll"&lt;/code&gt;&lt;code&gt;open System&lt;/code&gt; &lt;/p&gt;    &lt;p&gt;do      &lt;br /&gt;    let service = new TestWebServiceClient()       &lt;br /&gt;    let retVal = service.TestMethod "Nick"       &lt;br /&gt;    printfn "%s" retVal       &lt;br /&gt;    Console.ReadLine() |&amp;gt; ignore&lt;/p&gt;    &lt;p&gt;&lt;/p&gt;    &lt;p&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;This resulted in "Hello Nick" on the console. It was extremely simple to get this (albeit trivial) web service running.&lt;/p&gt;  &lt;p&gt;What I've not done yet is pass a more complex data contract, but that will come with in the next step, using LINQ-to-Sql to grab some data, and pass that back to the client.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131812"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131812" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/nickholmes/aggbug/131812.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Nick Holmes</dc:creator>
            <guid>http://geekswithblogs.net/nickholmes/archive/2009/05/05/an-f-wcf-web-service.aspx</guid>
            <pubDate>Tue, 05 May 2009 17:41:31 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/nickholmes/comments/131812.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/nickholmes/archive/2009/05/05/an-f-wcf-web-service.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/nickholmes/comments/commentRss/131812.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Curried Functions In C#</title>
            <link>http://geekswithblogs.net/nickholmes/archive/2009/05/05/curried-functions-in-c.aspx</link>
            <description>&lt;p&gt;I previously said that C#’s lambda functions were not curried, and it wasn’t possible to partially apply them. However, it’s usually possible to manually curry functions, if you need to. Here is an example:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;code&gt;static void Main(string[] args)       &lt;br /&gt;{        &lt;br /&gt;    int t = f(1)(3)(5)(7); &lt;/code&gt;      &lt;/p&gt;&lt;p&gt;    Console.WriteLine("{0}", t); &lt;/p&gt;      &lt;p&gt;    var g = f(1);       &lt;br /&gt;    var h = g(3);        &lt;br /&gt;    var i = h(5);        &lt;br /&gt;    int j = i(7); &lt;/p&gt;      &lt;p&gt;    Console.WriteLine("{0}", j);       &lt;br /&gt;} &lt;/p&gt;      &lt;p&gt;static Func&amp;lt;int, Func&amp;lt;int, Func&amp;lt;int, int&amp;gt;&amp;gt;&amp;gt; f(int a)       &lt;br /&gt;{        &lt;br /&gt;    return (b =&amp;gt; c =&amp;gt; d =&amp;gt; (a + b + c + d));        &lt;br /&gt;}&lt;/p&gt;    &lt;/blockquote&gt;  &lt;p&gt;It’s interesting to step through that code in Visual Studio. As the complex lambda expression is repeatedly returned to, the highlighting outlines exactly which sub-function is being evaluated. However, the return type of the f is not at all easy to read (although the new C# 3.0 var keyword means we don’t need to repeat this horror for g, h, &amp;amp; i). The equivalent code in F# is far more svelte:&lt;/p&gt;  &lt;blockquote&gt;   &lt;p&gt;&lt;code&gt;let f a b c d = a + b + c + d&lt;/code&gt;&lt;/p&gt; &lt;/blockquote&gt;  &lt;p&gt;Even with my cryptically short function name, its clear what this function does. There’s one more thing on curried functions I want to look at, but before that I’m going to look at implementing Web Services in F# and WCF.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131809"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131809" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/nickholmes/aggbug/131809.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Nick Holmes</dc:creator>
            <guid>http://geekswithblogs.net/nickholmes/archive/2009/05/05/curried-functions-in-c.aspx</guid>
            <pubDate>Tue, 05 May 2009 16:37:06 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/nickholmes/comments/131809.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/nickholmes/archive/2009/05/05/curried-functions-in-c.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/nickholmes/comments/commentRss/131809.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Do I have to have a curried function in F#?</title>
            <link>http://geekswithblogs.net/nickholmes/archive/2009/05/05/do-i-have-to-have-a-curried-function-in-f.aspx</link>
            <description>&lt;p&gt;All this currying and partial application stuff is all very interesting, but surely its has to have some kind of run-time performance hit. What if I just want to keep things straightforward?&lt;/p&gt;
&lt;p&gt;Firstly, if we have a function that takes only a single argument, there is nothing to curry. It makes no sense to call a function with no arguments, so your only option is to make the &lt;em&gt;exact&lt;/em&gt; call.&lt;/p&gt;
&lt;p&gt;That in mind, we can do this:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;let repeat(str, n) = ...&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;That syntax is sure to catch out C# programmers (like me), because it looks a lot like a normal C# function call. You might not even register, at first glance, the extra parenthesis around the arguments. However, these parenthesis are nothing to do with the function syntax, but everything to do with tuples:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;let name = ("Fred", "Smith")&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;here, name is equal to the pair of values “Fred” and “Smith”. Tuples can have more than 2 components. The type is reported as:&lt;/p&gt;
&lt;p&gt;&lt;em&gt;val x : string * string &lt;/em&gt;&lt;/p&gt;
&lt;p&gt;Personally, I find that * as the separator a bit jarring, but I assume there is a good reason to use it in preference to “,” - maybe it will come to light some day.&lt;/p&gt;
&lt;p&gt;Anyway, a tuple is a simple data structure that allows you to group 2 or more components into a single argument, and thereby create functions that need not be curried.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131808"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131808" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/nickholmes/aggbug/131808.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Nick Holmes</dc:creator>
            <guid>http://geekswithblogs.net/nickholmes/archive/2009/05/05/do-i-have-to-have-a-curried-function-in-f.aspx</guid>
            <pubDate>Tue, 05 May 2009 16:33:28 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/nickholmes/comments/131808.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/nickholmes/archive/2009/05/05/do-i-have-to-have-a-curried-function-in-f.aspx#feedback</comments>
            <slash:comments>2</slash:comments>
            <wfw:commentRss>http://geekswithblogs.net/nickholmes/comments/commentRss/131808.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Understanding F#&amp;rsquo;s Function Types, Part 3</title>
            <link>http://geekswithblogs.net/nickholmes/archive/2009/05/05/understanding-frsquos-function-types-part-3.aspx</link>
            <description>&lt;p&gt;In my last two posts, I described how F# transforms functions with more than one argument into chains of functions with a single argument. Strictly speaking, all functions in F# must have exactly one argument, and return exactly one result.  There is a special type, unit, which can be used as a dummy when no argument or return is required, like void in C#.&lt;/p&gt;  &lt;p&gt;F#’s functions are lambda functions, formally described by lambda calculus which provides the theoretic model for functional languages. Happily, we don’t all need to be fluent in lambda calculus to use F#. The F# compiler automatically converts functions to these chains of lambda functions in a process called &lt;em&gt;currying&lt;/em&gt;. The resulting function is said to be &lt;em&gt;curried -&lt;/em&gt; but remember the resulting function is just the first in the chain&lt;em&gt;.&lt;/em&gt; The term is named for Haskell Curry - for whom the Haskell language is also named (indeed there is another language called Curry too).&lt;/p&gt;  &lt;p&gt;Incidently C#’s lambda expressions are not curried automatically curried, and so its not possible to partially apply them.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131807"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131807" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/nickholmes/aggbug/131807.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Nick Holmes</dc:creator>
            <guid>http://geekswithblogs.net/nickholmes/archive/2009/05/05/understanding-frsquos-function-types-part-3.aspx</guid>
            <pubDate>Tue, 05 May 2009 16:30:22 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/nickholmes/comments/131807.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/nickholmes/archive/2009/05/05/understanding-frsquos-function-types-part-3.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/nickholmes/comments/commentRss/131807.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Understanding F#&amp;rsquo;s Function Types, Part 2</title>
            <link>http://geekswithblogs.net/nickholmes/archive/2009/05/05/understanding-frsquos-function-types-part-2.aspx</link>
            <description>&lt;p&gt;OK, so you define a function that takes 2 parameters, but you actually get a function that takes 1 parameter, and returns a function that will take the second parameter and return the final result. Hmm, this raises lots of questions.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What happens if the function has more than two parameters?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;&amp;gt;let f a b c = a + b + c&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;is of type&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;font face="Courier New"&gt;val f : int -&amp;gt; int -&amp;gt; int -&amp;gt; int&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;So we get a chain of functions, each one taking exactly one parameter, and returning a function that takes the next.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;If there are more that 2 parameters, can I partially apply more than one at a time?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;Following on from above, we can do:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;&amp;gt;let g = f 1 2&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;font face="Courier New"&gt;val g : (int -&amp;gt; int)&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;&amp;gt;g 3&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;em&gt;&lt;font face="Courier New"&gt;val it : int = 6&lt;/font&gt;&lt;/em&gt;&lt;/p&gt;
&lt;p&gt;This looks like F# functions can just accept a subset of their arguments, but remember that as f returns a function, what is really happening is the equivalent of this:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;let g = (f 1) 2&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;We are making a sequence of function calls. We could make the exact call like this:&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;((f 1) 2) 3&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;The consequence of this is that we can’t partially apply &lt;em&gt;any&lt;/em&gt; sub-set of the arguments. We still have to call the function chain in the correct order, which partially apply the arguments strictly from left to right.&lt;/p&gt;
&lt;p&gt;&lt;strong&gt;What happens to the partially applied arguments?&lt;/strong&gt;&lt;/p&gt;
&lt;p&gt;They are captured forever and immutably in the returned function.&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;let f a b = a + b&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;let g = f 1&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;let h = f 10&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;g will always return its argument plus 1, h always plus 10. f did not return the same function when called with different arguments.&lt;/p&gt;
&lt;p&gt;Strange as this last point seems to those of us more used to C#, this notion of capturing values into functions does exist in C#. Anonymous delegates capture the values of variables from their declaring method. In C# 3.0, lambda functions are a simpler syntax for these anonymous delegates. Here is an example.&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;static void Main(string[] args) &lt;br /&gt;
{ &lt;br /&gt;
    var g = f(1); &lt;br /&gt;
    var h = f(10); &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;    Console.WriteLine(”g(5) = {0}”, g(5)); &lt;br /&gt;
    Console.WriteLine(”h(5) = {0}”, h(5)); &lt;br /&gt;
    Console.WriteLine(”f(3)(5) = {0}”, f(3)(5)); &lt;br /&gt;
} &lt;/font&gt;&lt;/p&gt;
&lt;p&gt;&lt;font face="Courier New"&gt;static Func&amp;lt;int, int&amp;gt; f(int a) &lt;br /&gt;
{ &lt;br /&gt;
    return new Func&amp;lt;int, int&amp;gt;(x =&amp;gt; x + a); &lt;br /&gt;
}&lt;/font&gt;&lt;/p&gt;
&lt;p&gt;Similar result, ugly code!&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131806"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131806" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/nickholmes/aggbug/131806.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Nick Holmes</dc:creator>
            <guid>http://geekswithblogs.net/nickholmes/archive/2009/05/05/understanding-frsquos-function-types-part-2.aspx</guid>
            <pubDate>Tue, 05 May 2009 16:25:37 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/nickholmes/comments/131806.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/nickholmes/archive/2009/05/05/understanding-frsquos-function-types-part-2.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/nickholmes/comments/commentRss/131806.aspx</wfw:commentRss>
        </item>
        <item>
            <title>Understanding F#&amp;rsquo;s Function Types, Part 1</title>
            <link>http://geekswithblogs.net/nickholmes/archive/2009/05/05/understanding-frsquos-function-types-part-1.aspx</link>
            <description>&lt;p&gt;I’ve been spending some time recently looking at F# - I have a specific task in mind to which F# seems very well suited, so the motivation is there! After many years doing C then C++ and now C#, it’s easy to fall into the trap of thinking some things work just the same in F#.&lt;/p&gt;
&lt;p&gt;One example of this is functions. I was happily experimenting with some code, thinking I was getting the measure of F#, but one small detail kept catching my eye - the very strange types reported for functions.&lt;/p&gt;
&lt;p&gt;It all starts off simple enough - when you assign an expression to a value in F# Interactive, it reports back with the type it has inferred:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;gt;let myStr = "Hello World" &lt;br /&gt;
&lt;em&gt;val myStr : string&lt;/em&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Simple enough. Now what happens if we create a function:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;gt;let toStr n = sprintf "%d" n;; &lt;br /&gt;
&lt;em&gt;val toStr : int -&amp;gt; string&lt;/em&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;This makes perfect sense too, as we’ve created a function that takes an int and returns a string.&lt;/p&gt;
&lt;p&gt;Now lets add a second argument:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;gt;let makeTable n v = [| for i in 0..n -&amp;gt; v*i |];; &lt;br /&gt;
&lt;em&gt;val makeTable : &lt;strong&gt;int -&amp;gt; int -&amp;gt; int array&lt;/strong&gt;&lt;/em&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Initially, I could not see why F# reported the function type in such an unusual way. The function takes two arguments and returns an array, but the reported type reads “&lt;em&gt;a function that takes an int and returns a function that takes an int and returns an array&lt;/em&gt;“. Why so complex? If this was true, could we call the function with a single argument, and expect a new function back, like this…&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;gt;let partTable = makeTable 10;;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;Yes! that works:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&lt;em&gt;val partTable : (int -&amp;gt; int array)&lt;/em&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;When we call this function, its captured the first parameter, and completes as expected:&lt;/p&gt;
&lt;p&gt;&lt;code&gt;&amp;gt;partTable 9;; &lt;br /&gt;
&lt;em&gt;val it : int array [|0; 9; 18; 27; 36; 45; 54; 63; 72; 81; 90|]&lt;/em&gt;&lt;/code&gt;&lt;/p&gt;
&lt;p&gt;More on this to come.&lt;/p&gt;&lt;p&gt;&lt;a href="http://www.pheedo.com/click.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131805"&gt;&lt;img src="http://www.pheedo.com/img.phdo?x=6cda6ad746d942b9a1110d0715a4fa12&amp;u=131805" border="0"/&gt;&lt;/a&gt;&lt;/p&gt;&lt;iframe src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;PageID=31016&amp;amp;SiteID=1" width=1 height=1 Marginwidth=0 Marginheight=0 Hspace=0 Vspace=0 Frameborder=0 Scrolling=No&gt;
&lt;script language='javascript1.1' src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Browser=NETSCAPE4&amp;amp;NoCache=True&amp;PageID=31016&amp;amp;SiteID=1"&gt;&lt;/script&gt;
&lt;noscript&gt;&lt;a href="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Click&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" target="_blank"&gt;
&lt;img src="http://ads.geekswithblogs.net/a.aspx?ZoneID=5&amp;amp;Task=Get&amp;amp;Mode=HTML&amp;amp;SiteID=1&amp;amp;PageID=31016" width="1" height="1" border="0"  alt=""&gt;&lt;/a&gt;
&lt;/noscript&gt;
&lt;/iframe&gt;
&lt;img src="http://geekswithblogs.net/nickholmes/aggbug/131805.aspx" width="1" height="1" /&gt;</description>
            <dc:creator>Nick Holmes</dc:creator>
            <guid>http://geekswithblogs.net/nickholmes/archive/2009/05/05/understanding-frsquos-function-types-part-1.aspx</guid>
            <pubDate>Tue, 05 May 2009 16:17:57 GMT</pubDate>
            <wfw:comment>http://geekswithblogs.net/nickholmes/comments/131805.aspx</wfw:comment>
            <comments>http://geekswithblogs.net/nickholmes/archive/2009/05/05/understanding-frsquos-function-types-part-1.aspx#feedback</comments>
            <wfw:commentRss>http://geekswithblogs.net/nickholmes/comments/commentRss/131805.aspx</wfw:commentRss>
        </item>
    </channel>
</rss>