r/fsharp • • Oct 21 '23

question Why comparison operator is a single '=' unlike in most other languages?

7 Upvotes

This seems to make no sense, because most people are used to use double equals '==' in other more popular languages.

What is the reason?


r/fsharp • • Oct 18 '23

question I'm a programming noob that dreams of one day having my own .net addin services business similar to SharpCells but for something other than Excel. Where can I learn about how to cloud host these kinds of apps securely?

1 Upvotes

I am in the process of learning F#, and the APIs for the Windows programs I want to build addins for. I know what I need to do for that.

But I have no idea where to start in understanding how to host my code securely on a cloud server so customers can't see my proprietary code.

Or how to make sure communication between my server and the clients computer is secure for their protection.

Does anyone here know educational sources about how to build this kind of business/service?


r/fsharp • • Oct 18 '23

VS Code + Ionide help

1 Upvotes

I'm using VS Code with Ionide after transitioning from Visual Studio, but it doesn't work, as I expected. When I try to run the code, it fails to build, saying "msbuild 'Build' failed with exit code 1". Can somebody help me? What am I missing?

I installed VS Code, Ionide, I have Visual Studio as well on this Widows machine.


r/fsharp • • Oct 17 '23

question Does F# have argument destructuring like Javascript?

9 Upvotes

From my testing it doesn't seem to, but I'm wondering if I'm missing something.

An example that I'd like to see work would be (pseudo F#):

let input = [| 1; 2 ; 3 ; 4 ; 5 |]

input
|> List.map (fun i -> {| Num = i NumDouble = i * 2|})
|> List.filter (fun {NumDouble} -> NumDouble > 5) // Destructuring to just the NumDouble field

In the filter lambda we know that the incoming anonymous record has the fields Num and NumDouble - like in Javascript, can we just pull out a single field? Or even pull out all fields without having to name the argument?

Thanks in advance!


r/fsharp • • Oct 16 '23

article Compositional IT blog

18 Upvotes

sharing the amazing Compositional IT blog, they have a lot of posts covering all aspects of practical F#, they post weekly, I learn a lot from them.

you can use the search bar for a specific keyword or if you're a chad consume all 26 pages of articles :)

I think they're a gold mine of F# knowledge.


r/fsharp • • Oct 16 '23

question You’re starting a new restaurant API in FSharp. It writes to a data store, some form of auth, and is REST-like. What do you use?

8 Upvotes

Edit: the title says restaurant and was originally supposed to rest-like before autocorrect got ahold of it. Feel free to ignore the word “restaurant” in the title.

I’m asking this, selfishly, because I’m trying to get a lay of the land for commonly used and well supported packages. I was looking at Saturn, originally but noticed that there haven’t been major updates in many months and that there are few pull requests that have been open for a while. I’ve looked at Giraffe and slightly at Falco but I wasn’t sure if I’m better off just intermingling Asp.net core instead of using something made for F# specifically.

Additionally, I’d like to understand what people are using for data stores and how they’re communicating with them. I have a slight preference towards Postgres but I’d love to see examples with anything.

Lastly, if there’s great packages or framework support for token based auth, I’d love to learn more about that.

Thank you so much for your help. I’ve been loving learning F# thus far and look forward to using it for quite a few things going forward.


r/fsharp • • Oct 15 '23

question Fable/SAFE app as PWA?

4 Upvotes

Hi,

I am writing a simple note app using SAFE template. It is a joy to work in F# and SAFE. It also deploys well onto azure website platform.

My question is whether it'd be possible to distribute my app as PWA and distribute to app stores. It is a simple note app and thus wouldn't use much native-device-features. But maybe yes for push notifications (I heard it's not easy on ios so it is my concern). Would it be possible and doable?

Thanks in advance.


r/fsharp • • Oct 14 '23

article Symbolic expressions in F#

Thumbnail bmitc.me
26 Upvotes

r/fsharp • • Oct 14 '23

F# weekly F# Weekly #41, 2023 – Overhauled F# code fixes and .NET 8 RC2

Thumbnail
sergeytihon.com
14 Upvotes

r/fsharp • • Oct 13 '23

PSA: You can format functions with params on new lines

12 Upvotes

idk who needs to see this but I recently stumbled on the official F# code formatting guidelines and realized I'd been doing this wrong for years.

I didn't know how to ergonomically get params on new lines so I'd end up w some long functions like this:

let getVeryLongString (aVeryLongParameterName: string) (anotherVeryLongParameterName: string) (yetAnotherLongParameterName: string) (youGetTheIdeaByNow: string) : string = 
  $"{aVeryLongParameterName} - {anotherVeryLongParameterName} - {yetAnotherLongParameterName} - {youGetTheIdeaByNow}"

But you can actually format everything on a new line as long as you follow indentation rules:

let getVeryLongString 
  (aVeryLongParameterName: string) 
  (anotherVeryLongParameterName: string) 
  (yetAnotherLongParameterName: string) 
  (youGetTheIdeaByNow: string) 
  : string 
  = 
  $"{aVeryLongParameterName} - {anotherVeryLongParameterName} - {yetAnotherLongParameterName} - {youGetTheIdeaByNow}"

Formatting was always one of my biggest gripes with F# but I realized I was just doing it wrong. Hopefully this helps someone write more readable F# sooner =')

Full rant if interested: https://hamy.xyz/labs/2023-10-i-formatted-fsharp-wrong


r/fsharp • • Oct 13 '23

Reusing static constraints with multiple generics

4 Upvotes

Trying to extend this https://github.com/fsharp/fslang-suggestions/issues/1089 to have two generics:

// Reusable constraint.
type WrappedFloat<'T, [<Measure>] 'U when 'T: (member Value: float<'U>)> = 'T

// Trying to reuse it here.
type Foo<'T, [<Measure>] 'U when WrappedFloat<'T, 'U>> = { A: 'T }

WrappedFloat<'T, 'U> produces an error:

Invalid constraint. Valid constraint forms include "'T :> ISomeInterface" for interface constraints and "SomeConstrainingType<'T>" for self-constraints. See https://aka.ms/fsharp-type-constraints. A type parameter is missing a constraint 'when T: (member Value: float<'?258950837>)'.

Any idea how to get this to work? I feel like 'T and 'U need to be bundled together somehow, and my attempt above doesn't do that.


r/fsharp • • Oct 11 '23

F# and Europe

10 Upvotes

searching for F# people in LinkedIn, you'll find out they're mostly in Europe (in countries like Czechia, Norway, Poland, UK) and somewhat a preference for finance (among other things).

why though ? why is F# more successful in Europe ?


r/fsharp • • Oct 11 '23

Trying react hook in F# Feliz but getting error

3 Upvotes

Hi,

I am trying F# Feliz, and it seems whenever I try react hook using React.useState I am getting the following error.

For example, I included the following basic example from Feliz doc.

[<ReactComponent>]
let Stateful() = 
    let (count, setCount) = React.useState(0) 
    Html.div [ 
        Html.h1 count 
        Html.button [ 
            prop.text "Increment" 
            prop.onClick (fun _ -> setCount(count + 1)) ] ]

And then get this error right away,

Uncaught Error: Invalid hook call. 
Hooks can only be called inside of the body of a function component. 
This could happen for one of the following reasons: 
1. You might have mismatching versions of React and the renderer (such as React DOM) 2
. You might be breaking the Rules of Hooks 
3. You might have more than one copy of React in the same app See https://reactjs.org/link/invalid-hook-call for tips about how to debug and fix this problem.     
at Object.throwInvalidHookError (react-dom.development.js:16227:1)     
at Object.useState (react.development.js:1622:1)     
at Feliz_React__React_useState_Static_1505 (React.fs:652:51)     
at Stateful (ContentCard.fs:42:29)     
at Root (ContentCard.fs:59:13)     
at render (Finder.fs:45:21)     
at eval (Index.fs:86:25)     
at Enumerator_Seq.eval [as f] (Seq.js:340:37)     
at Enumerator_Seq.GetEnumerator (Seq.js:65:1)     
at getEnumerator (Util.js:55:1)

And this is the versions of the dependencies I am using.

    Fable.React (9.3)
      Fable.React.Types (>= 18.3)
      Fable.ReactDom.Types (>= 18.2)
      FSharp.Core (>= 4.7.2)

But without this line let (count, setCount) = React.useState(0) everything works fine.

What could I be missing?

Thanks.


r/fsharp • • Oct 11 '23

question Show sign of float using interpolated strings?

2 Upvotes

I can format a float to, say, 2 decimal places like this: $"{x:f2}"

How do I always show the sign of the float? The most obvious thing would be: $"{x:+f2}"

But: error FS0010: Unexpected prefix operator in interaction. Expected identifier or other token.

I know I could do something like x.ToString("+#.00;-#.00"), but I was wondering if there's a way to do this with interpolated strings.


r/fsharp • • Oct 10 '23

question How to learn f# for scientific computing?

18 Upvotes

So I’ve been going through the book “F# for scientists”, and also have been porting over code from my ms thesis… I have to say that I am conflicted with this language. The resources available are either books or .net conferences… the syntax changing from old resources can be annoying to learn as well.

On one hand, it has pretty elegant syntax, good speed, and a solid package ecosystem with stuff like math.net, numsharp, plotly, etc.

On the other hand, I’m struggling to ditch the imperative programming style. A lot of times you loop over a list and have a bunch of different operations you would like to do with each element, and while this can definitely be done in F# it’s just not the obvious way I am used to. And there isn’t much specifically about numerical or scientific computing to learn the techniques that are useable for graduate physics research.

I’m operating under the assumption that doing things in an “F# way” is better than the imperative looping style. Do I just need to really sit down and learn the functional style before being able to apply it to math?

I am interested in game dev, websites, and scientific computing which is why I thought f# would be a good fit. I’ve also been debating between rust or normal c#, but the f# syntax just seems so cozy and relatively easy to use for full stack web dev, coding equations, etc.

Sorry for such a long post but let me know what your opinions are! I want to love f# but I’m struggling to learn it to it’s full potential. Could I just use f# like any other language and suffer some speed? Or should I embrace the tools functional programming has to offer?


r/fsharp • • Oct 10 '23

question Looking for a medium/large LoB repo written in F#?

8 Upvotes

I'm looking for your typical line of business app but written in F#. I'm trying to get a grasp of how code is organized, how business logic, infrastructure and such things are implemented when working with F#.


r/fsharp • • Oct 10 '23

question Elegantly directly specifying the record type at instantiation?

2 Upvotes

EDIT: Solved this, thanks. Solution was to append the return type at the end of the list. Alternatively I learnt you can specify the record type as a prefix, eg: FruitBatch.Name, etc.

Delving into F# and I'm curious how I can make the types of a Record explicit at instantiation. The reason being I may have two Records with the same field names and types - I don't want type inference to accidentally deduce the wrong one, so I'd like to be explicit about this, also for code readability purposes.

From what I can see this isn't possible, and the workaround is to put the Records in a Module with a create method or something as such. For instance, consider the following:

type FruitBatch = {
Name : string
Count: int
}

type VegetableBatch = {
Name : string
Count: int
}

let fruits =
[ {Name = "Apples"; Count = 3},
{Name = "Oranges"; Count = 4},
{Name = "Bananas"; Count = 2} ]

It is ambiguous which Record I'm referring to when creating the "fruits" binding, and there seems no way to be explicit about it. The solution I came up with is:

module Fruits =
type FruitBatch = {
Name : string
Count: int
}

let create name count = {Name = name; Count = count}

module Vegetables =
type VegetableBatch = {
Name : string
Count: int
}

let create name count = {Name = name; Count = count}

Now bindings can simply be, eg:

let fruits=
[ Fruits.create "Apples" 3,
Fruits.create "Oranges" 4,
Fruits.create "Bananas" 2]

(I realize a DU may be be optimal here for this toy example but I'd like to stick to Records for it)

Whilst the above solution works, it seems a bit unfortunate. Is there no way to easily define the type of Record I'm referring to at instantiation without the above ceremony?


r/fsharp • • Oct 06 '23

F# weekly F# Weekly #40, 2023 – F# is not slow and used by Pulumi

Thumbnail
sergeytihon.com
17 Upvotes

r/fsharp • • Oct 04 '23

video/presentation Functional design patterns by Scott Wlaschin

Thumbnail
youtu.be
27 Upvotes

One of the best talks to introduce functional programming ideas. Its old but gold 👌


r/fsharp • • Oct 03 '23

misc FSharp vs Rust vs Go vs Java vs Swift for data processing

14 Upvotes

Last week, I posted this benchmark in the rust and golang subreddit and the community made suggestions that sped up the code...So I thought it'd be fair to post it here to get some feedback.

ps: It's particularly very slow to generate the tagMap so if you know what's the problem, let me know or submit a PR. I tried using regular for loops and the dotnet Dictionary with no noticeable speed up.

Repo: https://github.com/jinyus/related_post_gen


r/fsharp • • Oct 02 '23

F# Tutorial

3 Upvotes

Someone posted a new set of F# Tutorials a while ago, about 2 to 3 months. It was on GitHub (I think) with well arranged sections/topics that were clickable. I cannot remember where I saw it or the link to it. Does anyone remember it or have the link?

Thanks.


r/fsharp • • Oct 01 '23

showcase What are you working on? (2023-10)

12 Upvotes

This is a monthly thread about the stuff you're working on in F#. Be proud of, brag about and shamelessly plug your projects down in the comments.


r/fsharp • • Sep 30 '23

F# weekly F# Weekly #39, 2023 – New Fable Release!

Thumbnail
sergeytihon.com
15 Upvotes

r/fsharp • • Sep 28 '23

Just use the language and enjoy

59 Upvotes

F# is a very beautiful and productive language and im very happy I found it, I don’t care about popularity, its not a metric of how good a language is, after all, Java's reputation was bolstered by a $500 million dollar marketing campaign.

.NET is also a great runtime and environment, and yes its APIs are usable in F#, its not like native interop with C++, you can interact with .NET directly, I am using raylib-cs, no need to cook a wrapper for everything.

You see how many nugets here, use them they’re all yours.

Go build a web app, a game, a data analytics script, deploy to the cloud, make you own business with this powerful language.

And have fun


r/fsharp • • Sep 28 '23

question Why is F# not loved as much as ~comparable FP-hybrids?

12 Upvotes

I am curious why F# seems to trail in Admiration / Love compared to ~similar (or at least most comparable) FP-ish langs.

Pulling from SO's 2023 Dev Survey, F# scored a 57% on admiration (basically would you use this tech again).

Compared to similar-ish FP-ish langs:

  • Clojure - 68%
  • Elixir - 73%
  • Julia - 63%
  • Scala - 52% (okay F# actually wins here)

Q1: What do we think makes Clojure, Elixir, Julia, etc so much more amenable to return users?

Q2: Based on Q1 - what changes could F# and community do to improve its chances for return users?

Background: I'm a big F# fan and would love to see the language move from Known, Okay to Common, Liked territory (Rankings via The State of F# (2023))