<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Applied Lambda]]></title><description><![CDATA[Blog on  F#]]></description><link>https://appliedlambda.engineersnation.com</link><generator>RSS for Node</generator><lastBuildDate>Mon, 20 Apr 2026 15:44:25 GMT</lastBuildDate><atom:link href="https://appliedlambda.engineersnation.com/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[State Machines, cancellation token, and Concurrency Control in F#]]></title><description><![CDATA[Modern applications frequently perform long-running or I/O-bound operations such as HTTP downloads, file writes, or database calls. In F#, these are typically implemented using task { ... } or async { ... }. While the syntax looks sequential, the com...]]></description><link>https://appliedlambda.engineersnation.com/state-machines-cancellation-token-and-concurrency-control-in-f</link><guid isPermaLink="true">https://appliedlambda.engineersnation.com/state-machines-cancellation-token-and-concurrency-control-in-f</guid><category><![CDATA[C#]]></category><category><![CDATA[Functional Programming]]></category><category><![CDATA[networking]]></category><dc:creator><![CDATA[Amit Joshi]]></dc:creator><pubDate>Fri, 16 Jan 2026 11:50:41 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1768564231555/276f44e3-b72b-488c-b9f7-b6f9d2f61054.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Modern applications frequently perform long-running or I/O-bound operations such as HTTP downloads, file writes, or database calls. In F#, these are typically implemented using <code>task { ... }</code> or <code>async { ... }</code>. While the syntax looks sequential, the compiler transforms such code into a <strong>state machine</strong> under the hood.</p>
<p>Understanding how state machines, cancellation, and concurrency control work together is key to writing efficient, safe, and scalable asynchronous F# code.</p>
<hr />
<h2 id="heading-1-state-machines-the-foundation-of-async-execution">1. State Machines: The Foundation of Async Execution</h2>
<p>A <strong>state machine</strong> is a compiler-generated structure that allows an asynchronous function to pause and resume execution. Every time you use <code>do!</code> or <code>let!</code>, the function may suspend, freeing the current thread, and later resume from the same point.</p>
<p>Conceptually, an async download function progresses through states such as:</p>
<ul>
<li>Waiting for a semaphore  </li>
<li>Sending an HTTP request  </li>
<li>Receiving data  </li>
<li>Writing to disk  </li>
<li>Cleaning up resources  </li>
</ul>
<p>The F# compiler automatically tracks:</p>
<ul>
<li>The current execution state  </li>
<li>Local variables  </li>
<li>The next instruction after an await  </li>
</ul>
<p>Without this mechanism, developers would need to manually write callbacks or continuation chains. The state machine provides correctness, readability, and scalability with minimal effort.</p>
<pre><code class="lang-fsharp">task {
    <span class="hljs-keyword">do!</span> semaphore.WaitAsync()
    <span class="hljs-keyword">let!</span> bytes = client.GetByteArrayAsync(url)
    File.WriteAllBytes(path, bytes)
}
</code></pre>
<p>Although this looks linear, it is actually resumable and non-blocking.</p>
<p>You can think of the state machine as a bookmark in a book:</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>State</td><td>What happens</td></tr>
</thead>
<tbody>
<tr>
<td>0</td><td>Enter task, wait for semaphore (<code>WaitAsync</code>)</td></tr>
<tr>
<td>1</td><td>Semaphore acquired</td></tr>
<tr>
<td>2</td><td>HTTP request in progress</td></tr>
<tr>
<td>3</td><td>Write file to disk</td></tr>
<tr>
<td>4</td><td>Release semaphore</td></tr>
<tr>
<td>Done</td><td>Task completed</td></tr>
</tbody>
</table>
</div><p>The compiler remembers exactly where to resume execution after each awaited operation.</p>
<hr />
<h2 id="heading-2-cancellationtoken-cooperative-cancellation">2. CancellationToken: Cooperative Cancellation</h2>
<p>A <code>CancellationToken</code> provides a controlled stop mechanism for asynchronous operations. Instead of forcibly terminating tasks, cancellation in .NET and F# is <strong>cooperative</strong>.</p>
<p>Each async API periodically checks the token and throws <code>OperationCanceledException</code> when cancellation is requested.</p>
<pre><code class="lang-fsharp"><span class="hljs-keyword">let</span> cts = <span class="hljs-keyword">new</span> CancellationTokenSource()
downloadPdf cts.Token url
cts.Cancel()
</code></pre>
<p>This approach ensures:</p>
<ul>
<li>Resources are released safely  </li>
<li><code>finally</code> blocks still execute  </li>
<li>Partial work does not corrupt state  </li>
</ul>
<p>Cancellation tokens are essential for:</p>
<ul>
<li>User-initiated aborts  </li>
<li>Application shutdown  </li>
<li>Timeouts  </li>
<li>Cancelling queued or waiting operations  </li>
</ul>
<p>Think of a <code>CancellationToken</code> as a <em>stop button</em> that you pass into your async operations. When pressed, all observing tasks are notified and exit cleanly.</p>
<hr />
<h2 id="heading-3-semaphoreslim-controlling-parallelism">3. SemaphoreSlim: Controlling Parallelism</h2>
<p><code>SemaphoreSlim</code> limits the number of concurrent operations. This is critical when performing network- or disk-heavy tasks to avoid overwhelming the system or remote services.</p>
<pre><code class="lang-fsharp"><span class="hljs-keyword">let</span> semaphore = <span class="hljs-keyword">new</span> SemaphoreSlim(<span class="hljs-number">3</span>)

<span class="hljs-keyword">do!</span> semaphore.WaitAsync()
<span class="hljs-keyword">try</span>
    <span class="hljs-comment">// critical section</span>
<span class="hljs-keyword">finally</span>
    semaphore.Release() |&gt; ignore
</code></pre>
<p>With a semaphore:</p>
<ul>
<li>Only <code>maxParallel</code> tasks run simultaneously  </li>
<li>Excess tasks wait without consuming threads  </li>
<li>Throughput becomes predictable and stable  </li>
</ul>
<p>Example with <code>maxParallel = 3</code>:</p>
<pre><code>Slots: [X] [X] [X]

Tasks queued:
A | B | C | D | E | F

Step <span class="hljs-number">1</span>: A, B, C acquire slots → start HTTP
Step <span class="hljs-number">2</span>: D, E, F wait
Step <span class="hljs-number">3</span>: A finishes → slot released → D starts
Step <span class="hljs-number">4</span>: B finishes → slot released → E starts
Step <span class="hljs-number">5</span>: Cancellation requested → remaining tasks stop
</code></pre><p>The semaphore limits <em>active</em> states, while the state machine remembers where each task is paused.</p>
<hr />
<h2 id="heading-4-how-these-concepts-work-together">4. How These Concepts Work Together</h2>
<p>Each asynchronous task has its own internal state machine:</p>
<pre><code>[Task: downloadPdf url1]
State <span class="hljs-number">0</span>: Waiting <span class="hljs-keyword">for</span> semaphore
State <span class="hljs-number">1</span>: Semaphore acquired
State <span class="hljs-number">2</span>: HTTP request started
State <span class="hljs-number">3</span>: File written
State <span class="hljs-number">4</span>: Semaphore released → Done
</code></pre><p>If a cancellation token is triggered:</p>
<ul>
<li>Waiting tasks observe cancellation immediately  </li>
<li>Running tasks throw <code>OperationCanceledException</code> at their next check  </li>
<li><code>finally</code> blocks still run, releasing the semaphore  </li>
</ul>
<p>This cooperation between mechanisms is what makes F# async code both powerful and safe.</p>
<hr />
<h2 id="heading-5-the-role-of-gt-ignore">5. The Role of <code>|&gt; ignore</code></h2>
<p>You may often see code like this:</p>
<pre><code class="lang-fsharp">semaphore.Release() |&gt; ignore
</code></pre>
<p>The forward pipe operator <code>|&gt;</code> passes the value on the left into the function on the right.</p>
<p><code>ignore</code> is defined as:</p>
<pre><code class="lang-fsharp"><span class="hljs-keyword">val</span> ignore : <span class="hljs-symbol">'a</span> -&gt; unit
</code></pre>
<p>It simply discards a value. Since <code>Release()</code> returns an integer that is not needed, piping it into <code>ignore</code> makes the intent explicit.</p>
<hr />
<h2 id="heading-why-this-matters">Why This Matters</h2>
<p>Together, these concepts enable:</p>
<ul>
<li>Efficient use of threads  </li>
<li>Safe, cooperative cancellation  </li>
<li>Controlled concurrency  </li>
<li>Clean, maintainable asynchronous code  </li>
</ul>
<p>Without compiler-generated state machines, you would be forced to manually split logic into callbacks and continuations. F# hides that complexity while still giving you precise control over cancellation and parallelism.</p>
<p>Mastering these tools lets you write async code that scales gracefully and behaves predictably—even under heavy load.
```</p>
]]></content:encoded></item><item><title><![CDATA[.fsx vs .fs]]></title><description><![CDATA[Understanding F# Files: .fsx vs .fs (with a Practical stat.fsx Example)
When learning F#, one of the first confusions beginners face is the difference between .fsx files (F# scripts) and .fs files (source files part of a project). Understanding this ...]]></description><link>https://appliedlambda.engineersnation.com/fsx-vs-fs</link><guid isPermaLink="true">https://appliedlambda.engineersnation.com/fsx-vs-fs</guid><category><![CDATA[Functional Programming]]></category><category><![CDATA[Linux]]></category><dc:creator><![CDATA[Amit Joshi]]></dc:creator><pubDate>Sat, 20 Dec 2025 14:03:57 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1766239360598/67b0282e-d125-4780-9aba-7a3ba7e4877a.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-understanding-f-files-fsx-vs-fs-with-a-practical-statfsx-example">Understanding F# Files: <code>.fsx</code> vs <code>.fs</code> (with a Practical <code>stat.fsx</code> Example)</h1>
<p>When learning F#, one of the first confusions beginners face is the difference between <code>.fsx</code> files (F# scripts) and <code>.fs</code> files (source files part of a project). Understanding this distinction is essential for writing efficient scripts, experimenting, or developing full-fledged applications.</p>
<hr />
<h2 id="heading-1-fsx-f-script-files">1️⃣ <code>.fsx</code> — F# Script Files</h2>
<p><code>.fsx</code> files are <strong>interactive scripts</strong>, designed for <strong>quick prototyping, automation, or teaching</strong>. They are <strong>executed directly by F# Interactive (FSI)</strong> and <strong>do not require compilation</strong>.</p>
<h3 id="heading-key-features">Key Features:</h3>
<ul>
<li><p><strong>Execution:</strong> Interpreted top-to-bottom via <code>dotnet fsi script.fsx</code></p>
</li>
<li><p><strong>EntryPoint:</strong> Optional</p>
</li>
<li><p><strong>References:</strong> Can include packages or DLLs inline using <code>#r "..."</code></p>
</li>
<li><p><strong>Order Matters:</strong> Code runs sequentially as written</p>
</li>
</ul>
<p><strong>Use Case:</strong> Quick experiments, file processing scripts, teaching examples.</p>
<hr />
<h3 id="heading-example-statfsx-show-filedirectory-metadata">Example: <code>stat.fsx</code> — Show File/Directory Metadata</h3>
<p>This script demonstrates <strong>how to get size, last modified time, and permissions</strong> for files and directories:</p>
<pre><code class="lang-fsharp"><span class="hljs-keyword">open</span> System
<span class="hljs-keyword">open</span> System.IO

<span class="hljs-comment">/// Show metadata for a file or directory</span>
<span class="hljs-keyword">let</span> showStat path =
    <span class="hljs-keyword">if</span> File.Exists path <span class="hljs-keyword">then</span>
        <span class="hljs-keyword">let</span> f = FileInfo path
        printfn <span class="hljs-string">"File: %s"</span> f.FullName

    <span class="hljs-keyword">elif</span> Directory.Exists path <span class="hljs-keyword">then</span>
        <span class="hljs-keyword">let</span> d = DirectoryInfo path

        printfn <span class="hljs-string">"Last modified: %s"</span> (d.LastWriteTime.ToString())
    <span class="hljs-keyword">else</span>
        printfn <span class="hljs-string">"stat: cannot stat '%s': No such file or directory"</span> path

<span class="hljs-comment">/// Get command-line argument from FSI</span>
<span class="hljs-keyword">let</span> args =
    <span class="hljs-keyword">if</span> fsi.CommandLineArgs.Length &gt; <span class="hljs-number">1</span> <span class="hljs-keyword">then</span> fsi.CommandLineArgs.[<span class="hljs-number">1.</span>.] <span class="hljs-keyword">else</span> [||]

<span class="hljs-keyword">match</span> args <span class="hljs-keyword">with</span>
| [| path |] -&gt; showStat path
| _ -&gt; printfn <span class="hljs-string">"Usage: dotnet fsi stat.fsx &lt;file-or-directory&gt;"</span>
</code></pre>
<p><strong>Run the script:</strong></p>
<pre><code class="lang-bash">dotnet fsi stat.fsx /path/to/file
</code></pre>
<p>This is perfect for <strong>learning file I/O in F#</strong> and demonstrates a practical use of <code>.fsx</code> scripts.</p>
<hr />
<h2 id="heading-2-fs-f-source-files">2️⃣ <code>.fs</code> — F# Source Files</h2>
<p><code>.fs</code> files are <strong>part of a formal F# project</strong>. They are <strong>compiled</strong> using the project file (<code>.fsproj</code>) and produce a DLL or EXE.</p>
<h3 id="heading-key-features-1">Key Features:</h3>
<ul>
<li><p><strong>Execution:</strong> Compiled → run via <code>dotnet run</code> or referenced as a library</p>
</li>
<li><p><strong>EntryPoint:</strong> <code>[&lt;EntryPoint&gt;]</code> required for console apps</p>
</li>
<li><p><strong>References:</strong> Managed via <code>.fsproj</code> or NuGet</p>
</li>
<li><p><strong>Use Case:</strong> Multi-file applications, production software, libraries</p>
</li>
</ul>
<p><strong>Example:</strong> A console application, library, or large F# service.</p>
<hr />
<h2 id="heading-3-fsx-vs-fs-quick-comparison">3️⃣ <code>.fsx</code> vs <code>.fs</code> — Quick Comparison</h2>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Feature</td><td><code>.fsx</code></td><td><code>.fs</code></td></tr>
</thead>
<tbody>
<tr>
<td>Execution</td><td><code>dotnet fsi script.fsx</code></td><td><code>dotnet build</code> → <code>dotnet run</code></td></tr>
<tr>
<td>Build required</td><td>❌ No</td><td>✅ Yes</td></tr>
<tr>
<td>EntryPoint</td><td>Optional</td><td>Required for console apps</td></tr>
<tr>
<td>Multi-file</td><td>Less common</td><td>Standard</td></tr>
<tr>
<td>References</td><td>Inline (<code>#r</code>)</td><td>Project-managed (<code>.fsproj</code>)</td></tr>
</tbody>
</table>
</div><hr />
<h2 id="heading-4-when-to-use-which">4️⃣ When to Use Which</h2>
<ul>
<li><p><strong>Use</strong> <code>.fsx</code> for <strong>learning, scripting, automation, or experiments</strong>.</p>
</li>
<li><p><strong>Use</strong> <code>.fs</code> when building <strong>production applications, libraries, or multi-file projects</strong>.</p>
</li>
</ul>
<p>The <code>stat.fsx</code> example is a perfect demonstration of <code>.fsx</code> usage: a <strong>self-contained script</strong> that interacts with the filesystem, useful for both <strong>learning F# I/O</strong> and <strong>practical scripting</strong>.</p>
<hr />
<p>💡 <strong>Pro Tip:</strong> Start small with <code>.fsx</code> scripts to prototype functionality quickly. Once your logic stabilizes and your code grows, migrate it into a <code>.fsproj</code> project with <code>.fs</code> files for a more maintainable and production-ready structure.</p>
<hr />
]]></content:encoded></item><item><title><![CDATA[Why handleLs args Exists and handleDir(args) Doesn’t — A Type-Driven Lesson from F#]]></title><description><![CDATA[Why handleLs args — and Not handleDir(args)
A Theory-Driven Explanation from the F# Type System
When building a shell-like system in F#, it’s natural to think in terms of concepts.
You see a directory listing command and instinctively reach for a nam...]]></description><link>https://appliedlambda.engineersnation.com/why-handlels-args-exists-and-handledirargs-doesnt-a-type-driven-lesson-from-f</link><guid isPermaLink="true">https://appliedlambda.engineersnation.com/why-handlels-args-exists-and-handledirargs-doesnt-a-type-driven-lesson-from-f</guid><category><![CDATA[Functional Programming]]></category><dc:creator><![CDATA[Amit Joshi]]></dc:creator><pubDate>Wed, 17 Dec 2025 05:42:27 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1765949929151/fc9403bd-da55-4f9c-9a5f-ebc894674763.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h1 id="heading-why-handlels-args-and-not-handledirargs">Why <code>handleLs args</code> — and Not <code>handleDir(args)</code></h1>
<h3 id="heading-a-theory-driven-explanation-from-the-f-type-system">A Theory-Driven Explanation from the F# Type System</h3>
<p>When building a shell-like system in F#, it’s natural to think in terms of <em>concepts</em>.</p>
<p>You see a directory listing command and instinctively reach for a name like:</p>
<p>handleDir args</p>
<p>Then the compiler responds with something like:</p>
<p>FS0039: The value 'handleDir' is not defined. Maybe you want: handleLs, handleTree</p>
<p>At first glance, this feels like a trivial naming issue. Just rename the function, right?</p>
<p>But this error has nothing to do with directories.</p>
<p>It’s about <strong>symbol resolution, function contracts, and how F# encodes meaning through types</strong>.</p>
<hr />
<h2 id="heading-no-name-no-existence">No Name, No Existence</h2>
<p>F# is a statically typed, symbol-driven language.</p>
<p>A function exists <strong>only if it is explicitly defined and in scope</strong>. There is:</p>
<ul>
<li><p>no implicit meaning</p>
</li>
<li><p>no semantic guessing</p>
</li>
<li><p>no late binding</p>
</li>
</ul>
<p>If a symbol is not defined, it does not exist — full stop.</p>
<p>So when the compiler says “Maybe you want: <code>handleLs</code>, <code>handleTree</code>”, it’s not being helpful about spelling. It’s telling you something more important:</p>
<blockquote>
<p><em>The abstraction you tried to invent does not exist — but more precise ones already do.</em></p>
</blockquote>
<p>That’s where the real lesson begins.</p>
<hr />
<h2 id="heading-in-f-identity-comes-from-the-type-signature">In F#, Identity Comes from the Type Signature</h2>
<p>In F#, the <em>identity</em> of a function is not its name. It is its <strong>type signature</strong>.</p>
<p>The compiler does not reason about intent (“this is a directory command”). It reasons about contracts:</p>
<ol>
<li><p>How many arguments does the function take?</p>
</li>
<li><p>What are the types of those arguments?</p>
</li>
<li><p>What is the result type?</p>
</li>
</ol>
<p>This is why the difference between the following is <strong>semantic</strong>, not stylistic:</p>
<p>handleDiskInfo () handleLs args</p>
<hr />
<h2 id="heading-unit-vs-arguments-is-a-design-statement"><code>unit</code> vs Arguments Is a Design Statement</h2>
<p>The empty parentheses <code>()</code> represent the <code>unit</code> type.</p>
<p>A function that accepts <code>unit</code> is declaring something very specific:</p>
<blockquote>
<p><em>This operation takes no information from the caller.</em></p>
</blockquote>
<p>Its behavior is invariant. The caller cannot influence it.</p>
<p>That maps cleanly to commands like:</p>
<ul>
<li><p><code>df</code></p>
</li>
<li><p><code>uptime</code></p>
</li>
</ul>
<p>These commands are conceptually <strong>invoke-and-report</strong> operations.</p>
<p>By contrast, a function that accepts <code>string[]</code> is explicitly stating:</p>
<blockquote>
<p><em>My behavior depends on externally supplied input.</em></p>
</blockquote>
<p>That maps to commands like:</p>
<ul>
<li><p><code>ls</code></p>
</li>
<li><p><code>du</code></p>
</li>
<li><p><code>tree</code></p>
</li>
</ul>
<p>These commands represent a <strong>family of behaviors</strong>, parameterized by paths, flags, or options.</p>
<hr />
<h2 id="heading-unix-philosophy-enforced-at-the-type-level">Unix Philosophy, Enforced at the Type Level</h2>
<p>This distinction isn’t accidental — it’s Unix philosophy encoded into the type system.</p>
<div class="hn-table">
<table>
<thead>
<tr>
<td>Command Type</td><td>Conceptual Model</td><td>F# Signature</td></tr>
</thead>
<tbody>
<tr>
<td>Fixed behavior</td><td>Single invariant operation</td><td><code>unit -&gt; unit</code></td></tr>
<tr>
<td>Variable behavior</td><td>Parameterized family</td><td><code>string[] -&gt; unit</code></td></tr>
</tbody>
</table>
</div><p>Trying to collapse everything into a generic:</p>
<p>handleDir args</p>
<p>erases this distinction.</p>
<p>It pushes meaning out of the type system and into runtime logic — where it becomes harder to reason about, easier to misuse, and impossible for the compiler to enforce.</p>
<p>F# resists this <em>by design</em>.</p>
<hr />
<h2 id="heading-the-compiler-is-not-complaining-its-reviewing-your-design">The Compiler Is Not Complaining — It’s Reviewing Your Design</h2>
<p>When the compiler suggests <code>handleLs</code> or <code>handleTree</code>, it’s not saying:</p>
<blockquote>
<p>“You misspelled something.”</p>
</blockquote>
<p>It’s saying:</p>
<blockquote>
<p>“You already modeled this more precisely than what you’re attempting now.”</p>
</blockquote>
<p>This leads to the correct mental model:</p>
<p>F# function signature == command interface contract</p>
<ul>
<li><p>If a command conceptually varies with input, its function must accept parameters.</p>
</li>
<li><p>If it does not, its function must accept <code>unit</code>.</p>
</li>
</ul>
<p>This is not ceremonial verbosity. It is how correctness is enforced <em>early</em>, <em>mechanically</em>, and <em>without ambiguity</em>.</p>
<hr />
<h2 id="heading-the-real-takeaway">The Real Takeaway</h2>
<p>Static typing is often framed as a way to prevent mistakes.</p>
<p>That’s underselling it.</p>
<p><strong>Static typing prevents bad abstractions.</strong></p>
<p>It forces you to commit to a model of behavior — and makes imprecise models impossible to express.</p>
<p>Once you see this, the compiler stops feeling strict and starts feeling <em>honest</em>.</p>
<p>The syntax difference is just the surface. The rule underneath is the point.</p>
]]></content:encoded></item><item><title><![CDATA[Scala 3-Features]]></title><description><![CDATA[scala 3 main features
Scala has a fairly expressive type system with type inferencing.  get the benefit of both worlds - you can do statically checked duck typing with Scala.     
Other syntax improvements in Scala 3: Optional braces that support a d...]]></description><link>https://appliedlambda.engineersnation.com/scala-3-features</link><guid isPermaLink="true">https://appliedlambda.engineersnation.com/scala-3-features</guid><category><![CDATA[Scala]]></category><category><![CDATA[jvm]]></category><dc:creator><![CDATA[Amit Joshi]]></dc:creator><pubDate>Mon, 14 Nov 2022 08:57:12 GMT</pubDate><content:encoded><![CDATA[<h3 id="heading-scala-3-main-features">scala 3 main features</h3>
<p>Scala has a fairly expressive type system with type inferencing.  get the benefit of both worlds - you can do statically checked duck typing with Scala.     </p>
<p>Other syntax improvements in Scala 3:<br /> <strong>Optional braces</strong> that support a distraction-free, indentation-sensitive style of programming.
The new keyword is now optional.   </p>
<p>Type-level wildcards now _ to ?.
Implicits and their syntax have been revised.
New language features in Scala 3:<br />   implicits, using clauses can be specified by type,    </p>
<p>  <strong>Given instances</strong> allow programmers to determine the canonical value of a certain type, making programming with type-classes more straightforward,<br />  <strong>Extension methods</strong> are become inbuilt feature, display better error messages and improved type inference.<br />   <strong>Implicit conversions</strong> have been redesigned as instances of a type-class Conversion.<br />  A <strong>context functions</strong> feature makes contextual abstractions a first-class citizen, so now library authors can express concise domain-specific languages.       </p>
<h3 id="heading-type-system-improvements-in-scala-3">Type system improvements in Scala 3:-</h3>
<p> Enums, or enumerations, have been redesigned to blend well with case classes and form the new standard to express algebraic data types.
    Opaque type aliases enable developers to hide implementation details.
Intersection and union types enable the expression of type constraints outside the inheritance hierarchy.
    Polymorphic function types can abstract over functions that take type arguments along with value arguments.
    Type lambdas are type-level functions that can be passed as type arguments without needing an auxiliary type definition.</p>
<p><strong>Traits become similar to classes and also can accept parameters</strong>, .
<strong>Open classes require to mark classes as open</strong>.
Utility traits that implement behavior sometimes ought not be part of inferred types. With Scala 3, those traits can be marked as transparent, hiding the inheritance from the user.
Explicit null moves null out of the type hierarchy, for catching errors statically. Additional checks for safe initialization find access to unitialized objects.<br /><strong>Scala 3 also offers tools for metaprogramming</strong>, including compile-time operations, quoted code blocks, and an inline feature that allows values and methods to be reduced at compile time.
Inline.  the inline feature allows values and methods to be reduced at compile time.<br /><strong>Compile-time operations</strong>. The package scala.compiletime contains additional functionality that can be used to implement inline methods.<br />  <strong>Quoted code blocks</strong>. Scala 3 adds the new feature of quasi-quotation for code, providing a convenient high-level interface to construct and analyse code. Constructing code for adding one and one is as easy as '{ 1 + 1 }.<br />   <strong>Reflection API</strong>. For more advanced use cases quotes.reflect provides more detailed control to inspect and generate program trees.<br /><strong>Abstracting over contextual information</strong>. Using clauses allow programmers to abstract over information that is available in the calling context and should be passed implicitly. .<br /><strong>Providing Type-class instances</strong>. Given instances allow programmers to define the canonical value of a certain type. This makes programming with type-classes more straightforward without losing  implementation details.</p>
<p>   Viewing one type as another. Implicit conversions have been redesigned from the ground up as instances of a type-class Conversion.
    Higher-order contextual abstractions.
scala 3 now suggest Actionable feedback from the compiler. In case an implicit parameter cannot be resolved by the compiler, it now provides import suggestions that may fix the problem.</p>
<p>Parameterized enums
Enums can be parameterized.</p>
<p> The values of an enum correspond to unique integers. The integer associated with an enum value is returned by its ordinal method:     </p>
<pre><code>scala&gt; val green = Color.Green        


val red: Color = Green        


scala&gt; green.ordinal       


val res0: Int = <span class="hljs-number">0</span>
</code></pre><p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1668418363305/yqo8lywjG.png" alt="scala3_enum.png" /></p>
<p><strong>Opaque Types</strong>. Hide implementation details behind opaque type aliases without paying for it in performance<br /><strong>Intersection and union types</strong>. Basing the type system on new foundations led to the introduction of new type system features: instances of intersection types, like A &amp; B, are instances of both A and of B. Instances of union types, like A | B, are instances of either A or B.<br />Both constructs allow programmers to flexibly express type constraints outside the inheritance hierarchy.<br /><strong>Match types</strong>. Instead of encoding type-level computation using implicit resolution, Scala 3 offers direct support for matching on types. Integrating type-level computation into the type checker enables improved error messages and removes the need for complicated encoding.</p>
]]></content:encoded></item><item><title><![CDATA[Scala 3-Method-2]]></title><description><![CDATA[Defining Methods   
Scala 3 methods may contains many types of parameters:
Generic (type) parameters   
Default parameter     
Multiple parameter    
Context-provided parameters     
By-name parameters    
Method can be defined either with return or ...]]></description><link>https://appliedlambda.engineersnation.com/scala-3-method-2</link><guid isPermaLink="true">https://appliedlambda.engineersnation.com/scala-3-method-2</guid><category><![CDATA[scala3, ]]></category><category><![CDATA[Programming Blogs]]></category><category><![CDATA[programming languages]]></category><category><![CDATA[coding]]></category><dc:creator><![CDATA[Amit Joshi]]></dc:creator><pubDate>Tue, 04 Oct 2022 07:51:45 GMT</pubDate><content:encoded><![CDATA[<p><strong>Defining Methods</strong>   </p>
<h3 id="heading-scala-3-methods-may-contains-many-types-of-parameters">Scala 3 methods may contains many types of parameters:</h3>
<p>Generic (type) parameters   </p>
<p>Default parameter     </p>
<p>Multiple parameter    </p>
<p>Context-provided parameters     </p>
<p>By-name parameters    </p>
<p>Method can be defined either with return or without return:-  </p>
<p><code>def mulMethod(a: Int, b: Int): Int = a + b//method with return type</code>   </p>
<p><code>def mulMethod(a: Int, b: Int) = a + b//method without return type</code>   </p>
<p>The keyword <strong>def</strong> is used to define a method    </p>
<p>The Scala standard is to name methods using the <strong>camel case</strong> convention   </p>
<p>Method parameters are always defined with their type   </p>
<p>Declaring the method return type is optional   </p>
<p>Methods can be multi  lines, or just one line    </p>
<p>Here are two examples of a one-line method named add that takes two Int input parameters. The first method shows the method’s Int return type, and the second does not:</p>
<p>It is recommended to annotate publicly visible methods with their return type. Declaring the return type can make it easy, and readable.</p>
<p><strong>Calling methods</strong></p>
<h4 id="heading-invoking-a-method-is-simple">Invoking a method is simple:</h4>
<p><code>val p = mulMethod(5,4)</code>          </p>
<p>or          </p>
<p><code>val q = mulMethod(5,4)</code>     </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1664869742189/JbSGKBOkS.png" alt="Scala3.png" /></p>
]]></content:encoded></item><item><title><![CDATA[How to Install PostgreSQL on Ubuntu 20.04  Server]]></title><description><![CDATA[Install software certificates for a secure SSL connection
$ sudo apt install wget ca-certificates   

Add it to apt-key management utility and create a new configuration file with an official PostgreSQL repository address
$ wget --quiet -O - https://...]]></description><link>https://appliedlambda.engineersnation.com/how-to-install-postgresql-on-ubuntu-2004-server</link><guid isPermaLink="true">https://appliedlambda.engineersnation.com/how-to-install-postgresql-on-ubuntu-2004-server</guid><category><![CDATA[PostgreSQL]]></category><dc:creator><![CDATA[Amit Joshi]]></dc:creator><pubDate>Thu, 24 Mar 2022 09:20:01 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1648113520354/I69fWlxd6.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h4 id="heading-install-software-certificates-for-a-secure-ssl-connection">Install software certificates for a secure SSL connection</h4>
<p><code>$ sudo apt install wget ca-certificates</code>   </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1648112334211/rSRJzNL9B.png" alt="pgsql_1.png" /></p>
<h4 id="heading-add-it-to-apt-key-management-utility-and-create-a-new-configuration-file-with-an-official-postgresql-repository-address">Add it to apt-key management utility and create a new configuration file with an official PostgreSQL repository address</h4>
<p><code>$ wget --quiet -O - https://www.postgresql.org/media/keys/ACCC4CF8.asc | sudo apt-key add -</code>    </p>
<p><code>$ sudo sh -c 'echo "deb http://apt.postgresql.org/pub/repos/apt/ $(lsb_release -cs)-pgdg main" &gt;&gt; /etc/apt/sources.list.d/pgdg.list'</code>     </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1648112456765/B6-luP6G2.png" alt="pgsql_2.png" /></p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1648112467673/jRHmlJg33.png" alt="pgsql_3.png" /></p>
<h4 id="heading-install-postgresql">Install PostgreSQL</h4>
<p><code>$ sudo apt update</code>     </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1648112549112/-h4Finv68.png" alt="pgsql_4.png" /></p>
<p><code>$ apt install postgresql postgresql-contrib</code>    </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1648112594603/iyshIHYVQ.png" alt="pgsql_5.png" /></p>
<h4 id="heading-check-postgresql-status">Check PostgreSQL status</h4>
<p><code>$ service postgresql status</code>    </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1648112787123/522_nQ91j.png" alt="pgsql_6.png" /></p>
<h4 id="heading-command-line-tool">Command Line Tool</h4>
<p>A default admin user “postgres” is created by the default.  A “psql” command-line client tool is used to interact with the database engine.      </p>
<p><code>$ sudo -u postgres psql</code>    </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1648113009989/MeKQb-8Mg.png" alt="pgsql_7.png" /></p>
<p> PostgreSQL installation also creates a default database named “postgres” and connects you to it automatically when you first launch psql.    </p>
<h4 id="heading-check-the-connection">Check the connection</h4>
<p><code>$ \conninfo</code>  </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1648113109279/_PRaN2jKG.png" alt="pgsql_8.png" /></p>
<p>  If you want to see a list of all the databases that are available on a server, use \l command.    </p>
<p><code>$  \l</code>   </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1648113181526/6qX9V8GPh.png" alt="pgsql_9.png" /></p>
<p> list of all the users with their privileges use   </p>
<p><code>$ \du</code> </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1648113245133/6Dt0f_X8s.png" alt="pgsql_10.png" /></p>
<p>Since the default “postgres” user does not have a password, you should set it yourself.    </p>
<p><code>$ \password postgres</code>    </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1648113441457/xFB38IiZf.png" alt="pgsql_11.png" /></p>
]]></content:encoded></item><item><title><![CDATA[How to  create F# console app in Ubuntu]]></title><description><![CDATA[Create new folder and  give  following command:-
$ mkdir fsharpapplication
$ cd fsharpapplication        
$ dotnet new console --language F#     
     
Run the app:-
$ dotnet run]]></description><link>https://appliedlambda.engineersnation.com/how-to-create-f-console-app-in-ubuntu</link><guid isPermaLink="true">https://appliedlambda.engineersnation.com/how-to-create-f-console-app-in-ubuntu</guid><category><![CDATA[Functional Programming]]></category><dc:creator><![CDATA[Amit Joshi]]></dc:creator><pubDate>Tue, 22 Mar 2022 13:13:08 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1647954714134/lnqEcUXzj.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<h4 id="heading-create-new-folder-and-give-following-command">Create new folder and  give  following command:-</h4>
<p><code>$ mkdir fsharpapplication</code></p>
<p><code>$ cd fsharpapplication</code>        </p>
<p><code>$ dotnet new console --language F#</code>     </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1647954362938/xvuY3WGAQ.png" alt="consoleapp_f#_1.png" />     </p>
<h4 id="heading-run-the-app">Run the app:-</h4>
<p><code>$ dotnet run</code>   </p>
<p><img src="https://cdn.hashnode.com/res/hashnode/image/upload/v1647954568087/eKxrADI61.png" alt="consoleapp_f#_2.png" /></p>
]]></content:encoded></item></channel></rss>