<?xml version="1.0" encoding="utf-8" standalone="yes"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:content="http://purl.org/rss/1.0/modules/content/">
  <channel>
    <title>F-Sharp on AYU MAX</title>
    <link>https://ayumax.net/tags/f-sharp/</link>
    <description>Recent content in F-Sharp on AYU MAX</description>
    <image>
      <title>AYU MAX</title>
      <url>https://ayumax.net/profile.jpg</url>
      <link>https://ayumax.net/profile.jpg</link>
    </image>
    <generator>Hugo -- 0.147.1</generator>
    <language>en</language>
    <lastBuildDate>Wed, 22 Aug 2018 00:50:59 +0000</lastBuildDate>
    <atom:link href="https://ayumax.net/tags/f-sharp/index.xml" rel="self" type="application/rss+xml" />
    <item>
      <title>F# Study Today (Pattern Matching)</title>
      <link>https://ayumax.net/entry/2018/08/22/005059/</link>
      <pubDate>Wed, 22 Aug 2018 00:50:59 +0000</pubDate>
      <guid>https://ayumax.net/entry/2018/08/22/005059/</guid>
      <description>&lt;h1 id=&#34;f-review&#34;&gt;F# Review&lt;/h1&gt;
&lt;p&gt;Today I encountered pattern matching for the first time.&lt;/p&gt;
&lt;p&gt;C# has it too, but I felt this is a feature characteristic of F#.&lt;/p&gt;
&lt;h1 id=&#34;f-pattern-matching&#34;&gt;F# Pattern Matching&lt;/h1&gt;
&lt;p&gt;This is amazing. I thought C#’s switch expression pattern matching was similar, but this feature probably went from F# to C#.&lt;/p&gt;
&lt;h2 id=&#34;match-expression&#34;&gt;match Expression&lt;/h2&gt;
&lt;p&gt;I think the match expression will be used often, so I need to remember it well.&lt;/p&gt;
&lt;p&gt;Also, it seems there are different kinds of patterns like &lt;code&gt;or&lt;/code&gt; patterns and &lt;code&gt;as&lt;/code&gt; patterns, so I need to memorize these properly too.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<h1 id="f-review">F# Review</h1>
<p>Today I encountered pattern matching for the first time.</p>
<p>C# has it too, but I felt this is a feature characteristic of F#.</p>
<h1 id="f-pattern-matching">F# Pattern Matching</h1>
<p>This is amazing. I thought C#’s switch expression pattern matching was similar, but this feature probably went from F# to C#.</p>
<h2 id="match-expression">match Expression</h2>
<p>I think the match expression will be used often, so I need to remember it well.</p>
<p>Also, it seems there are different kinds of patterns like <code>or</code> patterns and <code>as</code> patterns, so I need to memorize these properly too.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-fsharp" data-lang="fsharp"><span style="display:flex;"><span><span style="color:#66d9ef">let</span> testFunc param <span style="color:#f92672">=</span>
</span></span><span style="display:flex;"><span>    <span style="color:#66d9ef">match</span> param <span style="color:#66d9ef">with</span>
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">|</span> <span style="color:#e6db74">&#39;a&#39;</span> <span style="color:#f92672">-&gt;</span> 0
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">|</span> <span style="color:#e6db74">&#39;b&#39;</span> <span style="color:#f92672">-&gt;</span> 1
</span></span><span style="display:flex;"><span>        <span style="color:#f92672">|</span> <span style="color:#f92672">_</span> <span style="color:#f92672">-&gt;</span> <span style="color:#f92672">-</span>1
</span></span><span style="display:flex;"><span>       
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">let</span> ret <span style="color:#f92672">=</span> testFunc <span style="color:#e6db74">&#39;b&#39;</span>
</span></span><span style="display:flex;"><span>printfn <span style="color:#e6db74">&#34;%A&#34;</span> ret
</span></span></code></pre></div><h2 id="function-expression">function Expression</h2>
<p>Simply put, it seems to be a combination of the <code>fun</code> expression and the <code>match</code> expression.</p>
<p>I thought it could be created with <code>if</code> statements even without <code>function</code>, but how is it really??</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-fsharp" data-lang="fsharp"><span style="display:flex;"><span><span style="color:#66d9ef">let</span> testFunc <span style="color:#f92672">=</span> <span style="color:#66d9ef">function</span> 
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">|</span> value <span style="color:#66d9ef">when</span> value <span style="color:#f92672">&gt;</span> 0 <span style="color:#f92672">-&gt;</span> 1
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">|</span> value <span style="color:#66d9ef">when</span> value <span style="color:#f92672">&lt;</span> 0 <span style="color:#f92672">-&gt;</span> <span style="color:#f92672">-</span>1
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">|</span> <span style="color:#f92672">_</span> <span style="color:#f92672">-&gt;</span> 0
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">let</span> ret <span style="color:#f92672">=</span> testFunc 2
</span></span><span style="display:flex;"><span>printfn <span style="color:#e6db74">&#34;%A&#34;</span> ret
</span></span></code></pre></div><h1 id="records">Records</h1>
<p>Is this equivalent to <code>class</code> in C#?</p>
<p>It doesn&rsquo;t seem to have functions though.</p>
<p>But to avoid side effects, is it better to create it by passing a record type as an argument?</p>
<p>Like C# extension methods.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-fsharp" data-lang="fsharp"><span style="display:flex;"><span><span style="color:#75715e">// Define the record type first
</span></span></span><span style="display:flex;"><span><span style="color:#75715e"></span><span style="color:#66d9ef">type</span> <span style="color:#a6e22e">Favorite</span> <span style="color:#f92672">=</span> <span style="color:#f92672">{</span> color<span style="color:#f92672">:</span> <span style="color:#66d9ef">string</span><span style="color:#f92672">;</span> number<span style="color:#f92672">:</span> int<span style="color:#f92672">;</span> music<span style="color:#f92672">:</span> <span style="color:#66d9ef">string</span> <span style="color:#f92672">}</span>
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">let</span> favorite <span style="color:#f92672">=</span> <span style="color:#f92672">{</span> color <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;red&#34;</span><span style="color:#f92672">;</span> number <span style="color:#f92672">=</span> 7<span style="color:#f92672">;</span> music <span style="color:#f92672">=</span> <span style="color:#e6db74">&#34;Jazz&#34;</span> <span style="color:#f92672">}</span> 
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">let</span> <span style="color:#f92672">{</span> color <span style="color:#f92672">=</span> favoriteColor<span style="color:#f92672">;</span> number <span style="color:#f92672">=</span> favoriteNumber<span style="color:#f92672">;</span> music <span style="color:#f92672">=</span> favoriteMusic<span style="color:#f92672">}</span> <span style="color:#f92672">=</span> favorite 
</span></span><span style="display:flex;"><span>printfn <span style="color:#e6db74">&#34;%s, %d, %s&#34;</span> favoriteColor favoriteNumber favoriteMusic
</span></span></code></pre></div><h1 id="discriminated-unions">Discriminated Unions</h1>
<p>My understanding of this is really low right now.</p>
<p>It&rsquo;s said to be close to <code>enum</code>, but since it can have associated values, it seems difficult to master.</p>
<p>But it feels like it would be satisfying if used well.</p>
<div class="highlight"><pre tabindex="0" style="color:#f8f8f2;background-color:#272822;-moz-tab-size:4;-o-tab-size:4;tab-size:4;"><code class="language-fsharp" data-lang="fsharp"><span style="display:flex;"><span><span style="color:#66d9ef">type</span> <span style="color:#a6e22e">Fruits</span> <span style="color:#f92672">=</span> 
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">|</span> Apple
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">|</span> Orange
</span></span><span style="display:flex;"><span>    <span style="color:#f92672">|</span> Grape
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span><span style="color:#66d9ef">let</span> favoriteFruits <span style="color:#f92672">=</span> Apple
</span></span><span style="display:flex;"><span>
</span></span><span style="display:flex;"><span>printfn <span style="color:#e6db74">&#34;%A&#34;</span> favoriteFruits
</span></span></code></pre></div><p>I&rsquo;m taking it slow, so that&rsquo;s all for today. I haven&rsquo;t even read half of the book yet, when will I finish&mdash;.</p>
]]></content:encoded>
    </item>
    <item>
      <title>Started Learning F#</title>
      <link>https://ayumax.net/entry/2018/08/17/002530/</link>
      <pubDate>Fri, 17 Aug 2018 00:25:30 +0000</pubDate>
      <guid>https://ayumax.net/entry/2018/08/17/002530/</guid>
      <description>&lt;h1 id=&#34;functional-programming&#34;&gt;Functional Programming&lt;/h1&gt;
&lt;p&gt;Honestly, I still don&amp;rsquo;t understand it well.&lt;br/&gt;
When should I choose it?&lt;br/&gt;
What are its advantages? To be honest, I don&amp;rsquo;t know.&lt;br/&gt;
Searching the web brings up things like &amp;ldquo;can write logic without side effects,&amp;rdquo; &amp;ldquo;code is easier to understand,&amp;rdquo; &amp;ldquo;testing is easier,&amp;rdquo; but I feel like I haven&amp;rsquo;t grasped the essence yet.&lt;br/&gt;
My image was that it&amp;rsquo;s a &amp;ldquo;language with a completely different way of thinking and usage from procedural languages,&amp;rdquo; and even if I memorized the meaning of arbitrary corresponding programming grammar, it wouldn&amp;rsquo;t mean I could actually use it. &lt;br/&gt;
That&amp;rsquo;s the strong impression I had – something in a realm I couldn&amp;rsquo;t touch.&lt;/p&gt;</description>
      <content:encoded><![CDATA[<h1 id="functional-programming">Functional Programming</h1>
<p>Honestly, I still don&rsquo;t understand it well.<br/>
When should I choose it?<br/>
What are its advantages? To be honest, I don&rsquo;t know.<br/>
Searching the web brings up things like &ldquo;can write logic without side effects,&rdquo; &ldquo;code is easier to understand,&rdquo; &ldquo;testing is easier,&rdquo; but I feel like I haven&rsquo;t grasped the essence yet.<br/>
My image was that it&rsquo;s a &ldquo;language with a completely different way of thinking and usage from procedural languages,&rdquo; and even if I memorized the meaning of arbitrary corresponding programming grammar, it wouldn&rsquo;t mean I could actually use it. <br/>
That&rsquo;s the strong impression I had – something in a realm I couldn&rsquo;t touch.</p>
<h1 id="f">F#</h1>
<p>Despite using C# for a long time, embarrassingly, I only learned about its existence recently.<br/>
I first learned about it at the Center CLR .Net600 study group I attended last year.<br/>
At that time, I was impressed that &ldquo;you can use a functional language with .Net&rdquo; and prepared my VS environment to use it, but I haven&rsquo;t touched it since then.</p>
<p>I think the main reason I didn&rsquo;t touch it was probably because I thought I needed to understand the underlying philosophy to use a functional language.</p>
<h1 id="reference-book">Reference Book</h1>
<p>Wanting to study F# properly, I was looking for books. Although it was published a little while ago, I found and purchased a book written by Mr. Arai, who also spoke at the aforementioned .Net600 event.<br/>
(I really wanted to buy it new, but couldn&rsquo;t find it, so I reluctantly bought it used.)</p>
<iframe style="width:120px;height:240px;" marginwidth="0" marginheight="0" scrolling="no" frameborder="0" src="https://rcm-fe.amazon-adsystem.com/e/cm?ref=tf_til&t=theotoku-22&m=amazon&o=9&p=8&l=as1&IS2=1&detail=1&asins=4774145165&linkId=92b183d41e10fbe7fac5da1f31494cf2&bc1=ffffff&lt1=_blank&fc1=333333&lc1=0066c0&bg1=ffffff&f=ifr">
    </iframe>
<p>I haven&rsquo;t finished reading it all yet, but as the book title suggests, it&rsquo;s written for beginners, so for now, it feels like the information is sinking in properly!</p>
<p>I wonder if it will get more difficult in the latter half, but I intend to read it through without giving up.
Lately, most information can be found online, but personally, I prefer having a book because I can concentrate better and absorb the information.</p>
<h1 id="just-try-it">Just Try It</h1>
<p>Because the fixed idea that &ldquo;functional languages are quite difficult&rdquo; occupied my mind, I was hesitant to start. However, I realized that if I stay like this, I&rsquo;ll never be able to use it, so I decided to just try touching it.<br/>
Fortunately, I&rsquo;ve been using C# for a long time, so I think F#, which uses the same .Net, will be easier to approach.
And I won&rsquo;t know what it&rsquo;s like unless I try.</p>
<p>If I hit a wall after trying, I&rsquo;ll think about what to do then!</p>
]]></content:encoded>
    </item>
  </channel>
</rss>
