title: Create an action in F# in order to use a c# method
body: <p>I would like to use this method from Owin implementation of HttpListener :</p>
  
  <pre><code>public static IDisposable Create(AppFunc app, IDictionary&lt;string, object&gt; properties)
  </code></pre>
  
  <p>AppFunc has a signature like this :</p>
  
  
  
  <pre class="lang-ml prettyprint-override"><code>IDictionnary&lt;string,Object&gt; -&gt; Task
  </code></pre>
  
  <p>I wanted to create a task but it requires an action, and I failed to know how to do it in F#.
  The best I managed so far was  using the code in this <a href="https://stackoverflow.com/questions/6836602/create-an-instance-of-actiont-using-reflection">question</a> :</p>
  
  <pre class="lang-ml prettyprint-override"><code>module CsharpAction
  
  open System
  
  type Wrapper&lt;'T&gt;(f:'T -&gt; unit) =
        member x.Invoke(a:'T) = f a
  
  let makeAction (typ:Type) (f:'T -&gt; unit) = 
      let actionType = typedefof&lt;Action&lt;_&gt;&gt;.MakeGenericType(typ)
      let wrapperType = typedefof&lt;Wrapper&lt;_&gt;&gt;.MakeGenericType(typ)
      let wrapped = Wrapper&lt;_&gt;(f)
      Delegate.CreateDelegate(actionType, wrapped, wrapped.GetType().GetMethod("Invoke"))
  </code></pre>
  
  <p>program.fs</p>
  
  <pre class="lang-ml prettyprint-override"><code>let yymmdd1 (date:DateTime) = date.ToString("yy.MM.dd")
      let printSuccess = fun() -&gt; printfn "Success %s" (yymmdd1 DateTime.Now )
      let actionTask = CsharpAction.makeAction (typeof&lt;string&gt;) (printSuccess)
      let mutable properties = Dictionary(dict [("fooKey", new Object())])
  
  
      let server = OwinServerFactory.Create((fun (props) -&gt; new  Task(actionTask)) , properties)
  </code></pre>
  
  <p>but then it tells me : <em>this expression was expected to have type action but here has type delegate</em></p>
  
  <p>Should I give from F# an action to c# code? or should I work on the c# code in order to give f# some niceties , for instance waiting for delegate instead of action ?</p>
  
  <p>I am flirting with the limits of my knowledge and I do feel the pain. Pretty sure, I will have to learn a lot, but if you would be so kind as to help me climb the first steps...</p>