/r/fsharp
This group is for people interested in the F# language, the functional-first language targeting .NET, JavaScript, and WebAssembly. More info about the language can be found at https://fsharp.org
F# is a multi-paradigm programming language compiling to both .NET ("normal") and JS (via "Fable").
Awesome F# is an aggregate of F# resources more actively maintained than this sidebar.
FSharp.org is an organization around F# promotion/adoption.
Language Documentation:
Learning Resources :
Video Channels :
Chat channels :
Web Development:
IDEs/Editor-Plugins:
Common:
Some extensions available:
Visual Studio Code with the Ionide plugin
Others:
/r/fsharp
I'm on the latest F#9
version, but running this
let f: string = null;;
val f: string = <null>;;
does not throw any error.
From what I understood, with the new non nullable reference types, this should emit a warning.
I have been coming across GADTs, but concretely I can't wrap my head around what they are. For example I tried to read https://practicalocaml.com/a-quick-guide-to-gadts-and-why-you-aint-gonna-need-them/ but I start to get lost when they get to the part where they generalize ADTs. Could someone explain a use case for GATs and what they might hypothetically look like in F# syntax?
🚀 Unlock the Power of Web Components! 🕸️
Join me, for a FREE event diving deep into:
✨ JavaScript & TypeScript
✨ F#
✨ Shadow DOM
✨ Custom Elements
✨ Declarative Shadow DOM
✨ Lit
📅 Dates: December 20th or 22nd (1.5 hours total)
🎓 Learn from an ex-Microsoft developer & F# enthusiast
🔗 Register Now: https://onur.works/web-components/
I try to plot a simple rectangle with gtksharp
The following code does not compile.
open Gtk
open Cairo
let main () =
Application.Init ()
let window = new Window ("Square Plot")
window.DefaultSize <- Gdk.Size(400,300)
let drawingArea = new DrawingArea ()
drawingArea.Drawn += fun drawingArea args -> // Error to many arguments.
let cr = args.Cr
cr.Rectangle (100.0, 100.0, 100.0, 100.0)
cr.SetSourceRGB (1.0, 0.0, 0.0)
cr.Fill ()
false
window.Add (drawingArea)
window.ShowAll ()
Application.Run ()
main ()
[ Note : the code comes more or less from Gemini. ]
So... I'm participating another year trying my best with F#, but when I go to the solutions megathread to compare my approach with others, there are just 2-3 f# people out there :( Quite demotivating... I'll share my repo,just in case anyone wants to take a look and throw some feedback. https://github.com/blfuentes/AdventOfCode_Main
It only has to run on linux, Cfr, https://github.com/fsprojects/awesome-fsharp?tab=readme-ov-file#gui
F# Raylib , how to plot a moving circle? A demo in Dlang, https://gitlab.com/alaindevos/dlangtut/-/blob/master/dub/69_raylib/source/app.d Currently I'm using DIKU.Canvas. https://gitlab.com/alaindevos/fhashtut/-/blob/master/b/109_plot/Program.fs
I am primarily a Java/Python programmer but I find the functional parts of F# really well designed. Once you get your head around it, the curried function syntax, match expressions, discriminated unions lead to very readable and succinct code
But the object oriented parts of F# are really a sore. Coming from Java it is hard to see why i need to say "member" in front of every method, and it is not even clear to me what is an instance member, a class member and just a variable defined inside a class body. There are just too many concepts to learn. Plus it does not play well with the functional parts of the language. One obvious thing is member functions need to take tuple arguments instead of curried arguments like normal functions.
Do you think it could have been better designed?
I need to create a black canvas of 200 by 200 pixels. And i need to have one function , plot a blue pixel at coordinates (100,100). If i can plot one pixel, i can plot anything.
Simple question, im a dev who likes to extract commonly used functions into static helper classes
Does anyone do the same but in f#?
Thanks
I think this warning is related to using "Xunit" unit testing.
/home/x/.nuget/packages/microsoft.net.test.sdk/17.12.0/build/netcoreapp3.1/Microsoft.NET.Test.Sdk.targets(48,5): warning : A 'Program.fs' file can be automatically generated for F# .NET Core test projects. To fix this warning, either delete the file from the project, or set the <GenerateProgramFile> property to 'false'. [/mnt/xxx_source/Languages_ok/fsharptut/b/107_option_bind/myprogram.fsproj]
What does this warning means. And how to get rid of it? Which exact line do I add to the fsproj file?
Hello is there a way to decompile F# into F# source code? I'm using ILSPy but it gives me very weird C#.
I have an option some(x) and i want to get the value of x. What is the adviced way to do so?
I expected the following program to print the data twice. It only prints it once. Why ?
open System
open System.IO
//open System.Linq
//open System.Collections.Generic
//open Xunit
//open FSharpx.Collections
let readFile path =
let reader = new StreamReader(File.OpenRead(path))
Seq.initInfinite (fun _ -> reader.ReadLine())
|> Seq.takeWhile (fun line -> line <> null)
type MyType = {
a:int
b:string
c:int
}
let parse (data:string seq):MyType option seq =
data
|> Seq.map
(fun (line:string) ->
let splits:string array=line.Split(" ")
match splits with
| [|_a ; _b ; _c|] ->
Some { a=_a |> int
b=_b
c=_c |> int
}
| _ -> None
)
[<EntryPoint>]
let main (args: string array) : int =
let filePath : string = "./test.txt"
let lines :string seq = readFile filePath
// for (line1:string) in lines do printfn "%s" line1
let result:MyType option seq = parse lines
let printIt = fun x -> printfn "%A" x
Seq.iter printIt result
Seq.iter printIt result
0
Hey folks! Today I'd like to show you how to use F# as a scripting language in Unity the easy way, it's all in this open source package right here: https://github.com/gilzoide/unity-fsharp
I've been interested in using F# in Unity for some time, but all packages/tools/ways I found to do it involved manual builds, lots of them made outside of Unity.
My approach is more integrated to the usual Unity workflow: you create F# scripts and when they change, the DLL is rebuilt automatically. The F# project automatically compiles all .fs
files, references all assemblies in the Unity project, including Assembly-CSharp
, and uses the same scripting symbols as C# does, like UNITY_EDITOR
, UNITY_STANDALONE
and DEVELOPMENT_BUILD
. Also, scripts inside Editor
folders are only available on the Unity Editor and cannot be used in player builds.
All of this using the latest .NET SDK (at the time of writing, version 9.0.100), which is automatically installed locally to the Library
folder. Later on we'll likely have a setting to change the install location and SDK version.
The built DLL, alongside FSharp.Core.dll
and all other package references, are copied over to the Assets/FSharpOutput
folder and imported by Unity. All you need to do really is write F# scripts, save them and let the plugin build the F# project automatically.
There's also the Assets/Editor/FSharpSettings
asset where you can define file compilation order and NuGet package references. Whenever something changes in the F# settings asset, the build runs again automatically after you deselect it. There's also a "Build" button in its Inspector, for manual builds.
This package is quite experimental, but I think it's ready enough for the world. I tested on Unity 2022 on Windows and Unity 2021 on macOS, but it will likely work on Linux and newer versions of Unity as well.
For those interested, please install the package via UPM (also available on OpenUPM), test it out and open issues/discussions on the GitHub repo. Also consider starring and sponsoring the project on GitHub ✨
That's it, cheers \o/
I don't know how to start. Which data-structures should i use ? The program should be able to ,1 create a list, 2 add an item to a list , 3 print the full list. If i know how to start then i can implement also other functions. ( I've written a program in D-lang. ) https://gitlab.com/alaindevos/dlangtut/-/blob/master/dub/66_list/source/app.d
Can the program below be optimised. For speed. (eg inline , how). Less boilerplate (eg wrapping functions). Or is it ok ?
open System
open Xunit
type IAnimal =
abstract member Name: string
abstract member Talk: string -> unit
type Chicken(name: string) =
//i:instance
member _.iName = name
member _.iTalk(msg: string) =
printfn $"My name is: {name}"
printfn $"Cluck: {msg}"
interface IAnimal with
member this.Name = this.iName
member this.Talk(msg: string) = this.iTalk (msg)
let animalFunction (a: IAnimal) : unit =
printfn ("I am the animalFunction")
printfn $"In the AnimalFunction i am called: {a.Name}"
a.Talk("Koekoek from animalFunction")
[<EntryPoint>]
let main (args: string array) : int =
printfn "Hello World \n"
let c = Chicken("Clucky")
c.iTalk ("Koekoek")
c |> animalFunction
0
I am learning F# and i know OpenTk is a very odd and difficult way to learn the language but i just want to render like shapes and planes and modify vertices z index.
Now what i am finding hard/confusing is that the configuration. The first thing i tried building with F# was a WPF desktop app wich i know is not dorectly supported for F# but non the less possible. I followed everything posted on yhe F# website about WPF apps and i kept getting an error that i found nothing on how to fix it online then i moved to avalonia and it worked fine.
For the 3d rendering i heard about Aardvark but same thing i installed packages copied codes to test and kept getting errors and same with OpenTk.
Can anyone here help know what exactly could i be doing wrong. Are there good up to date sources on how to use OpentTk with F#.
I am finishing a university course in Ocaml, and have an ok .NET background in C#. It appears the Ocaml to F# transition is pretty straightforward. Anyways, I'm looking for some of the more unique / fun ideas I could try and work on? Any suggestions? things your working on or maybe something from your portfolio? Looking beyond web app, and such.
The Functional Conf 2025 Call for Proposals is closing in less than a week, and it’s a golden opportunity to share your insights and innovative applications of functional programming with a vibrant community of like-minded individuals. Functional Conf is Asia’s premier functional programming conference, running 24-25 January 2025 (online).
Whether you have tackled a tricky problem using functional programming, developed a unique application, or have experiences that could enlighten your peers, we want to hear from you! We’re open to all topics related to functional programming.
We are seeking deep technical topics that push the boundaries of what’s possible with functional programming. Our commitment to diversity and transparency means all proposals will be public for community review.
Is your proposal unique? Is it well-developed and ready-to-go? Then you’ve got what it takes! Submit your ideas and help us make Functional Conf 2025 an unforgettable experience.
Submit your proposal today and help shape the future of functional programming!
Proposal submission deadline: 17 November at 23:59 IST
Im currently developing with MudBlazor and C# but Im always annoyed at C# and the way it always one step behind. So I stumbled upon F# and Bolero and saw Bolero is using Blazor to convert stuffs to wasm. So im thinking is Bolero + MudBlazor possible?
There was an active fsharp community member called fastfsharp that had quite well thought out YouTube videos and other content on performance oriented fsharp code. He seems to have disappeared
Hello,
I wrote me a little Bolero app with a client and a server which I want to put online. The application listen in dev mode on port 5000. So I would like to switch to https. Most probably this is super easy for the most dotNet developer, but I am a Java developer.
What I found out so far. Bolero uses the Kestrel webserver. There is a 'launchProperties.json' file which configures it. I can generate a certificate with 'dotnet dev-certs ..'. But here it ends for me.
Only the client has launch properties in the Properties folder. I start the server application to get the app running (Client+Server), which has no launch properties.
The launch properties of the client has a lot of port definitions, but none of them is 5000, which I used during the development. So basically I dont understand how they interact with each other.
Can somebody give me hint? I checked the source of the demo Bolero applications, but I found no https configuration, despite all of them running on https.
Has somebody an example configuration to spare?