<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Vin Yu</title>
    <description>The latest articles on DEV Community by Vin Yu (@rhemsta0).</description>
    <link>https://dev.to/rhemsta0</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F2108134%2Fd58c9eb7-81c8-4a04-8bdf-ac36290ddec9.png</url>
      <title>DEV Community: Vin Yu</title>
      <link>https://dev.to/rhemsta0</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/rhemsta0"/>
    <language>en</language>
    <item>
      <title>F# as a scripting language</title>
      <dc:creator>Vin Yu</dc:creator>
      <pubDate>Sun, 22 Sep 2024 14:40:52 +0000</pubDate>
      <link>https://dev.to/rhemsta0/f-as-a-scripting-language-2kf6</link>
      <guid>https://dev.to/rhemsta0/f-as-a-scripting-language-2kf6</guid>
      <description>&lt;p&gt;If you read on &lt;a href="https://learn.microsoft.com/en-us/dotnet/fsharp/tools/fsharp-interactive/" rel="noopener noreferrer"&gt;https://learn.microsoft.com/en-us/dotnet/fsharp/tools/fsharp-interactive/&lt;/a&gt;, F# language has an official interactive/interpreter support from Microsoft unlike C#. Let me know if I'm wrong guys please comment.&lt;/p&gt;

&lt;p&gt;This means you could use F# in places where you are using interpreted/scripting language like Python, Perl, Ruby&lt;/p&gt;

&lt;p&gt;Advantage you get to consume libraries from .NET ecosystem and strong type system of F#&lt;/p&gt;

&lt;p&gt;At this time of writing, I'm using dotnet sdk 8.0&lt;/p&gt;

&lt;p&gt;Step 1: Install paket&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet tool install -g paket
paket init
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Edit "paket.dependencies" and add your libraries you need.&lt;br&gt;
For this example, I want to add "FSharp.Core" version "8.0.300" and "UUIDNext" version "3.0.0"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;sources https://api.nuget.org/v3/index.json
storage: none

nuget FSharp.Core 8.0.300
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Step 2: Use "paket install" to install dependencies then "paket generate load-scripts --framework net8.0" to generate script to use to reference your dependencies in the script you will create&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;paket install
paket generate load-scripts --framework net8.0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;From one of the answers in stackoverflow, With the most recent cross plaform net installed and the most recent linux (coreutil 8.30&amp;lt;=) and bsd / mac os releases. You can use the following shebang for F# .fsx scripts.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/env -S dotnet fsi
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is a sample F# fsx script  I will create named "uuid.fsx"&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;#!/usr/bin/env -S dotnet fsi
#load @".paket/load/net8.0/main.group.fsx"


open System
open UUIDNext

let sequentialUuid = Uuid.NewDatabaseFriendly(Database.SQLite)
Console.WriteLine($"This is a database friendly UUID : {sequentialUuid}")
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;We can run this script from bash like we do with other scripts&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;./uuid.fsx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;or directly using dotnet command&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;dotnet fsi uuid.fsx
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Output:&lt;/strong&gt;&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;This is a database friendly UUID : 0191ea67-c7bf-77e6-af05-483dea4b1c62
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Nice!. we are done&lt;/p&gt;

&lt;p&gt;Reference: &lt;a href="http://www.970101.xyz/2024/09/f-as-scripting-language.html" rel="noopener noreferrer"&gt;http://www.970101.xyz/2024/09/f-as-scripting-language.html&lt;/a&gt;&lt;/p&gt;

</description>
    </item>
  </channel>
</rss>
