TinyFS.Core 0.0.2

dotnet add package TinyFS.Core --version 0.0.2
                    
NuGet\Install-Package TinyFS.Core -Version 0.0.2
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="TinyFS.Core" Version="0.0.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="TinyFS.Core" Version="0.0.2" />
                    
Directory.Packages.props
<PackageReference Include="TinyFS.Core" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add TinyFS.Core --version 0.0.2
                    
#r "nuget: TinyFS.Core, 0.0.2"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package TinyFS.Core@0.0.2
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=TinyFS.Core&version=0.0.2
                    
Install as a Cake Addin
#tool nuget:?package=TinyFS.Core&version=0.0.2
                    
Install as a Cake Tool

TinyFS

NuGet version NuGet version

Taking inspiration from the tinygo project.

F# for WebAssembly.

TinyFS is a F# to Wasm Compiler.

Leveraging the FSharp.Compiler.Service nuget package to generate an Abstract Syntax Tree (AST). Then walking the AST to generate Wasm bytes.

Current feature status:

  • Support for int32, int64, float32, float64 and bool primitives
  • The basic mathematical operators (+, -, *, /, %) are supported
    • % - modulo not supported by floating point primitives
  • The basic boolean operators (=, <>, >, >=, <, <=) are supported
  • Local parameters are supported, as well as mutable parameters.
  • if/else expression is supported
    • No elif yet
  • while...do

Installing as Nuget Tool

The fastest way to get started is to install via nuget tool.

  • Install a flavor of .NET 9 from microsoft
  • Run the following command: dotnet tool install --global TinyFS.Cli
    • To update if already installed: dotnet tool update -g TinyFS.Cli
  • You now have access to the tinyfs cli tool

Usage

How to compile and use.

  • Write a valid .fs program containing the supported fs syntax listed above/below
    • See examples to get started
    • Currently every *.fs file requires main function with a single unit parameter to exist
    • All code must be in a single .fs file, TinyFS does not currently support importing across files.
  • Run tinyfs compile <.fs file> to generate a wasm file
  • Run tinyfs run <.wasm file> to run the generated wasm
    • Can also run in any other wasm compliant runtime.
    • This leverages the wasmtime nuget package.
  • You can also use tinyfs compile -r <.fs file> to compile and run in one command.

Alpha Notice

⚠️⚠️⚠️⚠️⚠️⚠️

This is still alpha software, bugs are to be expected. The more complex the code, the more likely it will break.

By day I mainly program in C#, so I won't claim this library is optimized or error free. I mainly undertook this as a learning opportunity. There are currently no longer term plans for what this project will look like moving forward.

Feel free to raise an issue if you see something could be improved.

Supported Syntax

The easier a language construct is able to be mapped into WebAssembly the more likely it is to be implemented. I don't currently have any long term plans on what I'm planning on doing with this project.

Below lists the following language features that are supported.

Please see the examples folder for examples of compileable F# syntax that is ready to be used.

Basic Types

https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/basic-types

  • bool - by converting to WebAssembly's i32
  • byte
  • sbyte - by up converting to WebAssembly's i32
  • int16 - by up converting to WebAssembly's i32
  • uint16
  • int/int32
  • uint/uint32
  • long/int64
  • ulong/uint64
  • nativeint - probably never
  • unativeint - probably never
  • decimal
  • float32/single (32 bit)
  • float/double (64 bit)
  • char
  • string
  • unit
  • WebAssembly provides builtin support for int32, int64, float32 and float64. Everything else comes extra.

Language Constructs

  • let bindings
  • if...then...else
  • while...do loops
  • for...to loops
  • match expression
  • arrays
  • exception handling
  • generics
  • collections
  • types
  • tuples, options, results
  • records and untions
  • structs
  • object oriented programming (class, interfaces, etc)
  • reflection - probably never
  • computation expressions
  • async/task expressions

Operators

https://learn.microsoft.com/en-us/dotnet/fsharp/language-reference/symbol-and-operator-reference/

Arithmetic Operators

  • +
  • -
  • *
  • /
  • %
  • **

For currently supported primitive types

Comparison Operators

  • =
  • <>
  • <
  • <=
  • >
  • >=

For currently supported primitive types

Boolean Operators

  • &&
  • ||

For currently supported primitive types

Bitwise Operators

  • &&&
  • |||
  • <<<
  • >>>
  • ^^^
  • ~~~

Function Symbols and Operators

  • ->
  • |>
  • ||>
  • |||>
  • >>
  • <<
  • <|
  • <||
  • <|||

Other Features

  • Importing code across files
  • Building an entire *.fsproj file
  • Using standard library

How Is This Working

I'm using the FSharp.Compiler.Service nuget package to generate a usable Abstract Syntax Tree (AST) given F# code.

Then using what I learned in WebAssembly from the Ground Up for converting the F# AST to Wasm.

Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.0.2 204 2/26/2025
0.0.1 186 2/19/2025