{"id":996,"date":"2013-12-23T11:48:17","date_gmt":"2013-12-23T11:48:17","guid":{"rendered":"http:\/\/putridparrot.com\/blog\/?p=996"},"modified":"2013-12-23T11:48:17","modified_gmt":"2013-12-23T11:48:17","slug":"using-f-from-c","status":"publish","type":"post","link":"https:\/\/putridparrot.com\/blog\/using-f-from-c\/","title":{"rendered":"Using F# from C#"},"content":{"rendered":"<p>Let&#8217;s take a simple example &#8211; we have a library in F# which has functions that we want to use in C#. In this case we&#8217;ve got a Fibonacci function.<\/p>\n<ol>\n<li>Create a C# console application (for this demo)<\/li>\n<li>Add a new F# Library project (I named mine FLib)<\/li>\n<li>Add the following code to the library\n<pre class=\"brush: fsharp; title: ; notranslate\" title=\"\">\r\nnamespace FLib\r\n\r\nmodule Mathematics =\r\n\r\n    let rec fib n = if n &lt; 2 then 1 else fib (n - 1) + fib (n - 2)\r\n<\/pre>\n<p><em>Note: you must include the module if you want to declare values\/functions in a namespace<\/em>\n<\/li>\n<li>\nNow in the C# application add the using clause<\/p>\n<pre class=\"brush: csharp; title: ; notranslate\" title=\"\">\r\nusing FLib;\r\n<\/pre>\n<\/li>\n<li>And finally we use the function as per the following\n<pre class=\"brush: fsharp; title: ; notranslate\" title=\"\">\r\nint result = Mathematics.fib(5);\r\n<\/pre>\n<p>The module appears list a static class with static methods.\n<\/li>\n<\/ol>\n","protected":false},"excerpt":{"rendered":"<p>Let&#8217;s take a simple example &#8211; we have a library in F# which has functions that we want to use in C#. In this case we&#8217;ve got a Fibonacci function. Create a C# console application (for this demo) Add a new F# Library project (I named mine FLib) Add the following code to the library [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_jetpack_memberships_contains_paid_content":false,"footnotes":""},"categories":[6],"tags":[],"class_list":["post-996","post","type-post","status-publish","format-standard","hentry","category-f"],"jetpack_sharing_enabled":true,"jetpack_featured_media_url":"","_links":{"self":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/996","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/comments?post=996"}],"version-history":[{"count":7,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/996\/revisions"}],"predecessor-version":[{"id":1004,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/posts\/996\/revisions\/1004"}],"wp:attachment":[{"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/media?parent=996"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/categories?post=996"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/putridparrot.com\/blog\/wp-json\/wp\/v2\/tags?post=996"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}