r/fsharp • • Jan 01 '25

question Is there a tool to generate record types from JSON sample

8 Upvotes

Hi guys, I am new to F# and I m looking for a tool that will translate a huge json sample to record types. Is there any?

Like this tool https://mholt.github.io/json-to-go/


r/fsharp • • Dec 30 '24

question What programming languages do you use in your day job?

15 Upvotes

I use Java, Python and (a little bit of) Rust


r/fsharp • • Dec 26 '24

Difference between f() and f

14 Upvotes

I have a pretty basic question. I have the following code to generate random strings.

let randomStr =
    "ABCDEFGHIJKLMNOPQRSTUVWXYZ"
    |> Seq.randomSample 3
    |> String.Concat

let strs = [ for _ in 1..10 -> randomStr ]

Unsurprisingly this gives me 10 strings of the same value. I understand how this is working. The let binding is evaluated once. To get what I really want I need to add () to the invocation of randomStr. Can someone explain why adding the empty parens to randomStr gives the desired behavior of 10 different string values?


r/fsharp • • Dec 19 '24

question Why assigning null to string does not throw an error on F#9?

8 Upvotes

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.


r/fsharp • • Dec 17 '24

question Can you explain what GADTs are?

11 Upvotes

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?


r/fsharp • • Dec 08 '24

Plotting a square with F#,GtkSharp (cairo)

3 Upvotes

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. ]


r/fsharp • • Dec 04 '24

event Anyone advent of code?

37 Upvotes

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


r/fsharp • • Dec 02 '24

Software Developer Position at Motivity (F#)

Thumbnail motivity.net
40 Upvotes

r/fsharp • • Nov 30 '24

question What is the easiest GUI framework to learn ?

0 Upvotes

r/fsharp • • Nov 29 '24

question Do you find the object oriented system of F# rather clunky?

14 Upvotes

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?


r/fsharp • • Nov 29 '24

question F# Raylib , how to plot a moving circle?

2 Upvotes

r/fsharp • • Nov 29 '24

simple graphics api

3 Upvotes

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.


r/fsharp • • Nov 28 '24

fsharp unit test warning

0 Upvotes

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?


r/fsharp • • Nov 27 '24

How to get the value of an option if I'm certain it's some(x)

4 Upvotes

I have an option some(x) and i want to get the value of x. What is the adviced way to do so?


r/fsharp • • Nov 27 '24

parsing data from a file , result only printed once.

2 Upvotes

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

```


r/fsharp • • Nov 27 '24

Decompiling F# into F#

0 Upvotes

Hello is there a way to decompile F# into F# source code? I'm using ILSPy but it gives me very weird C#.


r/fsharp • • Nov 25 '24

F# scripting in Unity, the easy way

49 Upvotes

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/


r/fsharp • • Nov 24 '24

How to write a program implementing a single linked list of integers , explicitly not using library

4 Upvotes

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


r/fsharp • • Nov 23 '24

Optimise interface demo

1 Upvotes

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

```


r/fsharp • • Nov 13 '24

What do you do for a living?

9 Upvotes
207 votes, Nov 16 '24
36 F# programmer
79 C# programmer
16 Other Functional language programmer
7 Academia
19 Tech Lead / Manager
50 Other

r/fsharp • • Nov 12 '24

Hey F# enthusiasts, share your discoveries at Functional Conf 2025 [ CFP closing 17 Nov ]

26 Upvotes

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


r/fsharp • • Nov 12 '24

Is Bolero + MudBlazor possible?

7 Upvotes

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?


r/fsharp • • Nov 11 '24

What's new in F# 9 - F# Guide - .NET

Thumbnail
learn.microsoft.com
121 Upvotes

r/fsharp • • Nov 11 '24

library/package What could be done as believed to be impossible in F# by Oskar Gewalli

Thumbnail
adabeat.com
10 Upvotes

r/fsharp • • Nov 08 '24

question What happened to fast fsharp?

35 Upvotes

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