Answer by Tarmil for How to specify the result type for F# function's signature?
You can put a type annotation for the return value at the end of the declaration line:static member TryParse(s: string): SocialAccount option =As an aside, static member X = fun ... -> is not...
View ArticleAnswer by Tarmil for FParsec and postfix modifiers to parsed items
I think you can use opt to allow parseCount to not find a count if there isn't one:let parseCount = parseTerm .>>. opt (choice [ skipChar '*'>>% (MinCount 0) skipChar '+'>>% (MinCount...
View ArticleAnswer by Tarmil for What are the differences between in .fsx, .fsi and .fs...
.fsx is for individual files intended to run as a script. In particular, in an .fsx file you can use things like #r "Foo.dll" to dynamically load a library and #load "Foo.fsx" to load another script...
View ArticleAnswer by Tarmil for External JS library not applied to tag generated by...
The problem is that you have jQuery included twice: once by you manually in your index.html, and once by WebSharper automatically for its own purposes. So all the functionality added by TypeAhead and...
View ArticleAnswer by Tarmil for F# Async let! & return! computation expression
No, there are no default implementations for computation expression methods. If you want want special behavior for Async<'T option>, you can add an extension method to AsyncBuilder. It looks like...
View ArticleAnswer by Tarmil for F# create instance method for a constrained generic...
As mentioned by @brianberns in the comments, not directly. However, C#-style extension methods can be defined for a specialized version of a class. The caveat is that as an extension method, it won't...
View ArticleAnswer by Tarmil for Pattern match multiple dates
when can be added to a whole pattern, not to nested patterns, so you need something like this:match (startDate, endDate) with| d, e when d = DateTime.MinValue && e = DateTime.MinValue -> 0|...
View ArticleAnswer by Tarmil for Reflection doesn't work only with webassembly
As @JL0PD correctly guessed in their comment, this is because Bolero's tryfsharp runs an older compiler that doesn't support nameof.Updating it has been on my to-do list for ever, but there have been...
View ArticleAnswer by Tarmil for How do you override `GetHashCode()` idiomatically for an...
The recommended way to combine hash codes since .NET Standard 2.1 is using System.HashCode.Combine(). To differentiate between cases, you can add an integer argument.override this.GetHashCode() = match...
View ArticleAnswer by Tarmil for How to get Elmah working with .Net 6 F# Web Api Project
The equivalent in F#, and with asp.net minimal API that you are using, would be to put this before let app = ...:builder.Services.AddElmah<SqlErrorLog>(fun options -> options.ConnectionString...
View ArticleAnswer by Tarmil for Why Does F# Pattern Matching for a String Type Match a...
When you use an identifier in a pattern, you're not testing equality with an existing value (or type). Instead, you're defining a pattern that always matches, and giving the matched value the given...
View ArticleAnswer by Tarmil for How can I install the Fantomas Tool with the latest...
In version 5, the name of the package has changed from fantomas-tool to just fantomas. So you should uninstall fantomas-tool and install fantomas instead.
View ArticleAnswer by Tarmil for Why got "expected class or object definition" in very...
On Unix, fsc is the Scala compiler, not F#.Given how old Expert F# 4.0 is, I assume it suggested installing mono; in this case, the F# compiler is fsharpc.If you have the dotnet SDK instead, then the...
View ArticleAnswer by Tarmil for Apparent non-coherent behaviour between F# and C# when...
This is indeed a limitation in F#, you can't have a subtype constraint on two type parameters, ie 'T :> 'U. I think there's a language design suggestion to remove this limitation, although I can't...
View ArticleAnswer by Tarmil for Error when using MathNet.Numerics Fit.Line with F# tuple...
You should be able to use the struct keyword in the pattern part of let to deconstruct a struct tuple:let struct(Tau, Mu) = Fit.Line(shearRate, shearStress)
View ArticleAnswer by Tarmil for Moving FParsec code to an F# module does not work
As explained by @Gus in the comments, the problem is that parsers have a second type parameter for user data, that was disambiguated by the call to run in the original code but not in the modularized...
View ArticleAnswer by Tarmil for NullReferenceException in F# interactive
As @Jim Foye pointed out, the best way to go is to reference the package with #r "nuget:".As for why your original code throws an exception: the assemblies in the ref folder of a package, when there is...
View ArticleAnswer by Tarmil for What is a "sealed" type in F# and why doesn't the type...
Sealed types are a .NET concept. They are types that cannot be inherited from. This includes:F# recordsF# unionsF# classes declared with the [<Sealed>] attributeC# classes declared with the...
View Article