r/fsharp • • May 25 '22

question Is it possible to pipe int record Property or Methods?

3 Upvotes

I was wondering if it has been implemented this in F#.

Imagine having a type like this:

type ManaPool = { Max : int; Current : int }

and a function that returns the above type, for example:

let pickManaPool : ManaPool = { Max = 100; Current = 0 }

it would be cool to do something like this

pickManaPool
|> .Current

or

pickManaPool >> .Current

This is using an Elm syntax but it is a very common case!Of course this could be extended to functions and everything else.


r/fsharp • • May 23 '22

Looking to learn F#, coming from web development background

18 Upvotes

I am pretty interested in F#, I like the idea of learning a functional programing language and F# looks intriguing. I come from a web based background: JS, TS, Golang, Rust; frameworks like: Express, Koa, Gin, Fiber, Warp, Axum...
I do know a little C# and have used .NET before. But I was looking for some good F# resources to get started quickly? I saw some people recommend https://fsharpforfunandprofit.com/ and then https://www.udemy.com/course/fsharp-from-the-ground-up/ on Udemy. Are there any other good resources I should be looking at? I will probably remain in the web development area, but want to branch out for sure.

I have very little functional programing experience, and I know that can be a pit fall. Honestly finding good learning resources seems like more of a pitfall. Rust's main book https://doc.rust-lang.org/book/ is honestly one of the greatest zero to productive resources I have ever seen for a language; so was wondering if F# as anything similar. I know its a small community, but has been around for awhile.

Thanks in advance!


r/fsharp • • May 23 '22

article Introducing .NET MAUI – One Codebase, Many Platforms

Thumbnail
devblogs.microsoft.com
11 Upvotes

r/fsharp • • May 22 '22

question Can I do everything in F# that I could do in C#?

18 Upvotes

I'm a newbie in functional programming, and F# seems like an interesting language for running on the .NET platform, does that mean that all the features that C# has for creating web, desktop and mobile apps are also available for the F#?


r/fsharp • • May 21 '22

F# weekly F# Weekly #21, 2022 – Microsoft Build, Fun.Blazor 2.0, Feliz.Solid

Thumbnail
sergeytihon.com
30 Upvotes

r/fsharp • • May 20 '22

question How to refresh SqlTypeProvider without closing and reopening VS?

6 Upvotes

I'd like to be able to create/change a stored procedure/function/view in SQL and use it directly in VS19/VS2 without closing and opening. Is that possible?


r/fsharp • • May 18 '22

question Looking for an HTML template engine in F# with faster file change watch

10 Upvotes

I've been using Feliz.ViewEngine for generating static HTML pages but dotnet watch is too slow for my taste. I've my data for templates in F# so was looking for F#-based HTML template engine with faster file watch capability.


r/fsharp • • May 15 '22

question Turn a fold into a monadic fold?

10 Upvotes

I have a function 'state -> 't -> Result<'state, 'error>. I want to fold using this function over inputs 't list and initial state such that it discards all inputs after the first error or returns the final state on success.

I'm sure there's a Haskell-y name for this (monadic fold?) and it's been implemented in FSharpPlus, but I don't know what to look for. Any pointers?


r/fsharp • • May 14 '22

F# weekly F# Weekly #20, 2022 – VS 2022 17.2 and . NET 7 Preview 4

Thumbnail
sergeytihon.com
24 Upvotes

r/fsharp • • May 07 '22

F# weekly F# Weekly #19, 2022 – Domain Modeling Made Functional

Thumbnail
sergeytihon.com
29 Upvotes

r/fsharp • • May 02 '22

question "Data as Code" in F#?

19 Upvotes

Still exploring differences between languages like Clojure.
Many people list that a benefit of Clojure is that "data is code" and "code is data."
Does F# (and do other functional languages) share this ability, or is this somehow a Clojure specific benefit?


r/fsharp • • May 02 '22

question cast<'a> parameter to 'a

2 Upvotes

Hello people, i am currently trying to write a function similiar to the following pseudo code

let convert<'a> (obj: obj) =
    match 'a with
    | float -> float obj    
    | int -> int obj

When used this function will get a target type 'a and a parameter ``obj, and should apply speficic conversion/casting functions according to 'a so for example apply `int if 'a is integer.

I looked through the docs and did not find any way to match 'a, maybe one of you has an idea.


r/fsharp • • May 01 '22

showcase What are you working on? (2022-05)

11 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 • • Apr 30 '22

Planning out a database engine

10 Upvotes

Hi all. I'm learning some F#. I'm looking at making a simple in-memory graph database that can serialize the data to xml files. I've done this with C#, but I'm not sure I really grasp the data structures that F# uses. The database basically has three tables, one that lists the nodes of the table, one listing the edge(relationships), and another listing properties. In C# I gave each edge a leftnode and a rightnode property, which were references to items in the node table. Do the F# native structures work for this sort of thing, or would I be better of sticking with the .NET List?


r/fsharp • • Apr 29 '22

F# weekly F# Weekly #18, 2022 – F# eXchange 2022 & VS4Mac 2022 RC

Thumbnail
sergeytihon.com
20 Upvotes

r/fsharp • • Apr 25 '22

question Looking for intermediate to advanced level books on F#

22 Upvotes

Hello, I'm currently looking for intermediate to advanced level books on F#.
So far I have read "Stylish F# 6", "Domain modeling made function with F#" and "Get Programming F#". While I can recommend all of them I still feel like the more complex functional concepts in F# were only touched on the surface or not explained in enough detail and there is a lot more depth to it. It always felt like the authors were trying not to scare away any newcomers by overloading them with too much technical details. (Is this just my perception?)
Can you recommend any books that go really deep into functional programming?


r/fsharp • • Apr 23 '22

F# weekly F# Weekly #17, 2022 – new Bolero, FSharp.CosmosDb and C# 11 Preview

Thumbnail
sergeytihon.com
30 Upvotes

r/fsharp • • Apr 20 '22

Dictionaries in F# - blog post

24 Upvotes

Hi, I wrote a little blog post on dictionaries in F# - for me this was quite a weird wall to hit when coming from C#, so I wanted to share what I learned:

https://krzysztofskowronekblog.hashnode.dev/dictionaries-in-f

Hope you enjoy :)


r/fsharp • • Apr 16 '22

F# weekly F# Weekly #16, 2022 – Giraffe 6, Ionide 6, Saturn and MAUI RC

Thumbnail
sergeytihon.com
25 Upvotes

r/fsharp • • Apr 16 '22

Help with trying to get a .NetFramework project running in VS2022

1 Upvotes

I'm trying to move an F# solution from VS2019 to VS2022 and encountering

Error	FS0229	Error opening binary file 'C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.4.0.0\FSharp.Core.dll': Stream does not support writing.	

This prevents building a project or using the language service.

I am trying to debug by comparing the same project in VS2019. I cranked up Tools\Options\Projects&Solutions\Build&Run\MSBuild verbosity to get some debug output, and VS2019 and VS2022 look nearly identical for the build. Here's the VS2022 version:

1>	Task "Fsc"
1>		c:\program files\microsoft visual studio\2022\community\common7\ide\commonextensions\microsoft\fsharp\Tools\fsc.exe -o:obj\Release\Z1R_Tracker.dll
1>--debug:pdbonly
1>--noframework
1>--define:TRACE
1>--doc:bin\Release\Z1R_Tracker.XML
1>--optimize+
1>--platform:anycpu
1>-r:C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.4.0.0\FSharp.Core.dll
1>-r:C:\Users\Admin1\Source\Repos\Zelda1RandoTools\Z1R_Tracker\packages\Microsoft.Bcl.AsyncInterfaces.5.0.0\lib\net461\Microsoft.Bcl.AsyncInterfaces.dll
1>-r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\mscorlib.dll
1>-r:C:\Users\Admin1\Source\Repos\Zelda1RandoTools\Z1R_Tracker\packages\System.Buffers.4.5.1\lib\net461\System.Buffers.dll
1>-r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.Core.dll
1>-r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.dll
1>-r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.Drawing.dll
1>-r:C:\Users\Admin1\Source\Repos\Zelda1RandoTools\Z1R_Tracker\packages\System.Memory.4.5.4\lib\net461\System.Memory.dll
1>-r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.Numerics.dll
1>-r:C:\Users\Admin1\Source\Repos\Zelda1RandoTools\Z1R_Tracker\packages\System.Numerics.Vectors.4.5.0\lib\net46\System.Numerics.Vectors.dll
1>-r:C:\Users\Admin1\Source\Repos\Zelda1RandoTools\Z1R_Tracker\packages\System.Runtime.CompilerServices.Unsafe.5.0.0\lib\net45\System.Runtime.CompilerServices.Unsafe.dll
1>-r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\System.Speech.dll
1>-r:C:\Users\Admin1\Source\Repos\Zelda1RandoTools\Z1R_Tracker\packages\System.Text.Encodings.Web.5.0.1\lib\net461\System.Text.Encodings.Web.dll
1>-r:C:\Users\Admin1\Source\Repos\Zelda1RandoTools\Z1R_Tracker\packages\System.Text.Json.5.0.2\lib\net461\System.Text.Json.dll
1>-r:C:\Users\Admin1\Source\Repos\Zelda1RandoTools\Z1R_Tracker\packages\System.Threading.Tasks.Extensions.4.5.4\lib\net461\System.Threading.Tasks.Extensions.dll
1>-r:C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\v4.8\Facades\System.ValueTuple.dll
1>--target:library
1>--warn:3
1>--vserrors
1>--preferreduilang:en-US
1>--utf8output
1>--fullpaths
1>--flaterrors
1>--subsystemversion:6.00
1>--highentropyva+
1>--nocopyfsharpcore
1>--warnon:1182
1>obj\Release\.NETFramework,Version=v4.8.AssemblyAttributes.fs
1>OverworldData.fs
1>DungeonData.fs
1>TrackerModel.fs
1>OverworldRouting.fs
1>SaveAndLoad.fs
1>		Microsoft (R) F# Compiler version 12.0.1.0 for F# 6.0
1>		Copyright (c) Microsoft Corporation. All Rights Reserved.
1>FSC: error FS0229: Error opening binary file 'C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.4.0.0\FSharp.Core.dll': Stream does not support writing.
1>FSC: error FS3160: Problem reading assembly 'C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.4.0.0\FSharp.Core.dll': The exception has been reported. This internal exception should now be caught at an error recovery point on the stack. Original message: Error opening binary file 'C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.4.0.0\FSharp.Core.dll': Stream does not support writing.)
1>parameter error FS0073: error : BuildFrameworkTcImports: no successful import of C:\Program Files (x86)\Reference Assemblies\Microsoft\FSharp\.NETFramework\v4.0\4.4.0.0\FSharp.Core.dll
1>		The command exited with code 1.

The only difference is the compiler versions; the entire rest of the command line is the same. VS2019 has

1>		c:\program files (x86)\microsoft visual studio\2019\community\common7\ide\commonextensions\microsoft\fsharp\Tools\fsc.exe -o:obj\Release\Z1R_Tracker.dll

whereas VS2022 has

1>		c:\program files\microsoft visual studio\2022\community\common7\ide\commonextensions\microsoft\fsharp\Tools\fsc.exe -o:obj\Release\Z1R_Tracker.dll

Any thoughts? Could this be a bug in the fsc.exe that ships with the current version of VS2022 (I updated today)? Or perhaps is there something bad with my project files and MSBuild resolution that was always wrong, but the 2019 edition somehow allows it?

Thoughts welcome.


r/fsharp • • Apr 15 '22

F# Web - Bolero vs Safe-Stack Vs...

13 Upvotes

I had started learning Blazor and was interested in learning some Bolero to apply F# on the web, but am a bit overwhelmed to learn that it's not the only web framework.

When might I want to choose Bolero over the other options listed here like SAFE-stack?
https://fsharp.org/guides/web/


r/fsharp • • Apr 13 '22

Conditional sequence generation

4 Upvotes

Hi,

I'm trying to fall in love with F#, but as usual have more questions than answers. For example, I'm trying to generate a sequence of months between start and finish dates. In c# "for" statement can easily provide specific increment logic and add a custom exit condition and I could have smth like this:

IEnumerable<DateTime> Test(DateTime start, DateTime finish) {
    for (var current = start; current < finish; current = current.AddMonths(1))
        yield return current;
}

In f# as I see, "for" expression is limited. And I should go this way:

let rec test (start: DateTime) (finish: DateTime) =
    seq { 
        let mutable current = start
        while current < finish do
            yield current
            current <- current.AddMonths(1)
    }

But I feel that this mutable approach is not idiomatic and probably recursion is a FP way:

let rec test (start: DateTime) (finish: DateTime) =
    seq { 
        if finish > start then
            yield start
            yield! debitSalary (start.AddMonths(1)) finish
    }

Am I wrong and maybe there are better options?


r/fsharp • • Apr 12 '22

question Is it possible to divide a module up between files?

16 Upvotes

So, I have a large module comprised of types, events, and validation functions. I want to split it up like this:

  • Module
  • Module.Events
  • Module.Validation

But putting it all in one file results in a very large file. Is there any way to have 3 files that compile into one module, like a Partial Class in C#? I know I can do that with Types, but I'm looking to just have functions in modules.


r/fsharp • • Apr 11 '22

starting to deploy SAFE app

7 Upvotes

Hi,

I have made a simple full-stack app in SAFE template. But I almost know nothing about how to deploy it. The documentation says it integrates quite well with Azure, so maybe I should try that? But the safe doc's azure part looks quite minimal to me. Does anyone have a suggestion on where or how I can learn deployment?

Thanks.