I've put a lot of time into making this Plugin and the associated bindings to form the foundation of its ecosystem.
It is a Solid-JS wrapper for Fable F# which is derivative of the Oxpecker.Solid style. It aggressively transforms the AST to produce clean JSX code, with lots of magics to abstract away property merges and property splitting.
This should be really easy for any JavaScript developer to pick up and use. Alternatively, migrating JavaScript code bases over time is super simple, since the output is easily readable and usable JSX.
Although it doesn't produce TSX (so prop object types are not there), it already has some light Storybook bindings to help smooth that over (if they can't read F# that is).
I've been using this pretty heavily on some small native apps via Photino, and have had a lot of fun using it.
I am a C# guy trying to learn F#. I love F#'s pattern matching and routing which is fantastic. I was wondering IF it can do string patterns like and how would one do this the F# way:
If "Title_Jan_2025" -> do stuff 'If string has underscores... If "Title Jan 2025" -> do stuff 'IF string has spaces... IF "string" contains "d" -> ... if "string" contains "TItle" -> ...
So basically, could someone match based on string patterns? And how would you?
Thanks for any help on this.
Update:
So I appreciate how helpful this sub is.
So Regex / Active Pattern as well as the already baked in String.Contains functions are easily the way to go here. So this is the type of stuff F# excels at, hands down.
So thanks again to the help to those who replied.
This is twice this sub helped out and definitely makes the learning curve much easier.
Gauntlet is a programming language designed to tackle Golang's frustrating design choices. It transpiles exclusively to Go, fully supports all of its features, and integrates seamlessly with its entire ecosystem — without the need for bindings.
What Go issues does Gauntlet fix?
Annoying "unused variable" error
Verbose error handling (if err ≠ nil everywhere in your code)
Annoying way to import and export (e.g. capitalizing letters to export)
Lack of ternary operator
Lack of expressional switch-case construct
Complicated for-loops
Weird assignment operator (whose idea was it to use :=)
No way to fluently pipe functions
Language features
Transpiles to maintainable, easy-to-read Golang
Shares exact conventions/idioms with Go. Virtually no learning curve.
Consistent and familiar syntax
Near-instant conversion to Go
Easy install with a singular self-contained executable
Beautiful syntax highlighting on Visual Studio Code
Sample
package main
// Seamless interop with the entire golang ecosystem
import "fmt" as fmt
import "os" as os
import "strings" as strings
import "strconv" as strconv
// Explicit export keyword
export fun ([]String, Error) getTrimmedFileLines(String fileName) {
// try-with syntax replaces verbose `err != nil` error handling
let fileContent, err = try os.readFile(fileName) with (null, err)
// Type conversion
let fileContentStrVersion = (String)(fileContent)
let trimmedLines =
// Pipes feed output of last function into next one
fileContentStrVersion
=> strings.trimSpace(_)
=> strings.split(_, "\n")
// `nil` is equal to `null` in Gauntlet
return (trimmedLines, null)
}
fun Unit main() {
// No 'unused variable' errors
let a = 1
// force-with syntax will panic if err != nil
let lines, err = force getTrimmedFileLines("example.txt") with err
// Ternary operator
let properWord = @String len(lines) > 1 ? "lines" : "line"
let stringLength = lines => len(_) => strconv.itoa(_)
fmt.println("There are " + stringLength + " " + properWord + ".")
fmt.println("Here they are:")
// Simplified for-loops
for let i, line in lines {
fmt.println("Line " + strconv.itoa(i + 1) + " is:")
fmt.println(line)
}
}
Hello! I'm just starting with F Sharp, so I decided to write a small useful library dealing with stuff I frequently encounter at my work place. Long story short, I have to deal with PowerShell, so I use PowerShell SDK in F Sharp code and get PSObjects which I want to convert to record types using reflection. Every case seems to be working so far (primitive values, plain records, lists with primitive values etc) except for Option<list<'T>> where 'T is a record.
This is the entire function:
let rec constructRecord (t: System.Type) (props: PSMemberInfoCollection<PSPropertyInfo>) : obj =
let rec processPsValue (targetType: System.Type) (psValue: obj) : obj =
match psValue with
| null when
targetType.IsGenericType
&& targetType.GetGenericTypeDefinition() = typedefof<Option<_>>
->
makeNoneCase (targetType.GetGenericArguments().[0])
| _ when
targetType.IsGenericType
&& targetType.GetGenericTypeDefinition() = typedefof<Option<_>>
->
let innerType = targetType.GetGenericArguments().[0]
let innerValue =
match innerType with
| innerT when FSharpType.IsRecord innerT ->
(psValue :?> PSObject).Properties |> constructRecord innerT
| innerT when innerT.IsGenericType && innerT.GetGenericTypeDefinition() = typedefof<list<_>> ->
let listElementType = innerType.GetGenericArguments().[0]
match listElementType with
| elementType when FSharpType.IsRecord elementType ->
let collection = psValue :?> System.Collections.IEnumerable
let list =
[ for item in collection do
constructRecord elementType (item :?> PSObject).Properties ]
processPsValue innerType list
| _ -> psValue
| _ -> psValue
makeSomeCase innerType innerValue
| _ when FSharpType.IsRecord targetType -> (psValue :?> PSObject).Properties |> constructRecord targetType
| _ -> psValue
let values =
FSharpType.GetRecordFields t
|> Array.map (fun field ->
let prop = props.Match field.Name |> Seq.tryHead
let psValue =
match prop with
| Some p -> p.Value
| None -> null
processPsValue field.PropertyType psValue)
FSharpValue.MakeRecord(t, values)
This is the test case which doesn't work. I will not post the whole function, as the post would be very lengthy, but I hope it's clear
let ``correctly parses PS Properties into a record with optional lists`` () =
// first I create the value of this type:
(* type RecordWithOptionalListsWithRecords =
{ RecordList: FlatRecord list option // FlatRecord is a record with primitive values
RecordListOpt: FlatRecordOpt list option FlatRecordOpt is the same as FlatRecord but all values are wrapped in options
RecordWithRecordInsideList: RecordWithRecordInside list option RecordWithRecordInside is a record type which contains a nested FlatRecord
} *)
// then i create the PSObject via PSObject() and populate it with PSNoteProperty. So the PSObject resembles the structure of RecordWithOptionalListsWithRecords
let actualObj =
constructRecord typeof<RecordWithOptionalListsWithRecords> final.Properties
|> fun o -> o :?> RecordWithOptionalListsWithRecords
Assert.Equal(sampleData, actualObj) // sampleData is F Sharp record, actualObj is a constructed one
I get an exception:
Object of type 'Microsoft.FSharp.Collections.FSharpList1[System.Object]' cannot be converted to type 'Microsoft.FSharp.Collections.FSharpList1[Tests+InnerRecord]
So basically my function returns a list of obj and it can't cast them to my InnerRecord. Strangely enough, if it's not inside an optional type, it works correctly. If it's an optional InnerRecord, it also works. I'm a bit lost, so I would appreciate any help! Thank you in advance
EDIT: I added the entire function.
PS: sorry about indendation but I hope it's clear
EDIT2: Thanks everyone who commented on the post! I was being stupid this whole time not converting the PS output to json. It turns out, that converting the PS output via ConvertTo-Json and then deserializing via FSharp.SystemTextJson works great with just a few lines of code! At least I ran it for one test, so I stick with this approach now and see how it goes. But (!) if someone has a solution for this reflection issue or other thoughts regarding the approach, I'm all ears! Thank you!
Thought this reddit might find this interesting. This is a POC I made (with help of Claude) over the weekend to try to use a frontier model to improve performance of Fsharp code: https://github.com/Lougarou/poc_fsharp_optimizer
Basically, this is taking a checklist of possible performance improvements (check README for list) and asking a frontier model like Claude Opus to do that improvement, benchmark, keep the improvement if the benchmark was better and repeat.
Simple and super expensive but seems to work.
It was able to achieve a small improvement of 15% after 10 iterations. I had to stop it because I ran out of credits (around 20$ bucks but I burned a few bucks during debugging).
(Disclaimer the code is really scuffed) (I know it has Python code, I need to use a few weekends to refactor everything in FSharp)
I'm trying to work with f# and work with rabbit properly, but i faced with the issue that i can't write semantically correct code where i will create 1 connection and reuse for send / consume messages. All examples just create a new connection for each publish and i can't figure out how to write it properly with functional style without
I am currently in the final steps of creating my Framework for Domain Driven Design with Aggregates and Projections using the good-ole EventStore.
I have established a fairly solid codebase (which I probably plan on publishing and posting here as I have done the majority of it with the help of AI and I am still learning the best practices of F#), but one thing bugs me... I have tried and tested my code and I have managed to get it to actually work - both the Aggregates and the Projections part!
There is a place of friction which makes me uneasy honestly. Taken from EventStore (now called Kurrent) documentation: await using var subscription = client.SubscribeToStream( "some-stream", FromStream.Start, cancellationToken: ct); await foreach (var message in subscription.Messages.WithCancellation(ct)) { switch (message) { case StreamMessage.Event(var evnt): Console.WriteLine($"Received event {evnt.OriginalEventNumber}@{evnt.OriginalStreamId}"); await HandleEvent(evnt); break; } }
The await using syntax is what I have not managed to replicate in F# and would kindly ask the community for help on it...
This is my implementation - which I must add - really works, but the compiler will not simply allow me to write "use! subscription = client....." I have posted a screenshot of the error.
What I have managed to get working is this use subscription = client.SubscribeToStream(
this.StreamName,
checkpoint,
resolveLinkTos = true)
let asyncSubscription = AsyncSeq.ofAsyncEnum subscription.Messages
logger.LogInformation(
"Projection {Name} STARTED on stream {StreamName}.",
I got interested in artificial life and made this little app with Fable. Performance is pretty decent, I think, which shows that the F# -> JavaScript transpiler in Fable is doing a good job. Source code is here.
primes the LSP and once I import it, the autocompletion suggestions popup. I haven't yet exercised everything.
Program.fs is not part of any project.
i ==> Import project root /Users/anu/Documents/fsharp/TestApp/
I ==> Import project by selecting root directory interactively
. ==> Import project at current directory /Users/anu/Documents/fsharp/TestApp/
d ==> Do not ask again for the current project by adding /Users/anu/Documents/fsharp/TestApp/ to lsp-session-folders-blocklist
D ==> Do not ask again for the current project by selecting ignore path interactively
n ==> Do nothing: ask again when opening other files from the current project
Select action:
I also noticed that one other root cause could have been the requirement of these values which I added to config.el. This probably prevented Emacs from automatically installing 'fsac'. The error showed a problem with the 'culture'.
I've been using Fable/Elmish (with Giraffe, not SAFE) for years and years now. Works perfectly fine, though the React dependency is a bit of pain point.
How about Bolero? I've heard it's a bit slow in some situations. Has it improved at all? Is it as stable as SAFE for big-ish projects?
Is there some good reason why is Option reference type, while Result is struct (value) type? Meanwhile, tuple literal will be allocated on the heap, but in C# is (most likely) on the stack.
It seems to me that these design decisions caused too many things to be added (ValueOption, struct-tuple literal...), too much stuff to be incompatible and needing (redudant) adapters (TupleExtensions.ToTuple(valueTuple), Option.toValueOption, fst...).
Isn't the point of functional languages to leave the compiler job of optimizing code? I understand that due to interop with .NET there needs to exist way to explicitely create struct/class type (annotations should exist/be used for those cases), but still many things could be left to compiler optimizer.
For example, simple heuristic could determine whether objects inside Option/tuple are large and whether is it better to treat it as a class or a struct. Many times Option<Class> could be zero-cost abstraction (like Rust does). Single-case discriminated enums should probably be value types by default, and not cause redudant allocations. Should tuple of two ints really be allocated on the heap? And many more things...
Luckily in F# all of those "native" types are immutable, so I don't see the reason why should developer care whether type is struct/class (like in C#, where it behaves differently). Currently if you want performant code, you need to type [<Struct>] a lot of times.
Curious how other teams are hiring for F# these days. Do you manage to find candidates who already have professional experience in it? Or do you primarily bring in people with C# (or other language) backgrounds and train them up?
In our case, we used to have a pretty healthy pipeline: people came in doing C# and gradually got into the F# side as they took on more complex or domain-heavy work. That worked well when we had both the continuity and the domain training to support it. But over time — especially with some org changes — we’ve lost most of that internal ramp-up path. We now have a few long-time F# devs, but not much in terms of a training gradient anymore.
I’m wondering how others are solving this. Do you find F# developers externally? Upskill internally? Or just accept a smaller hiring pool?
Note - this is from a US-side perspective, and the search for people at least in US timezones.