f#

For loop not inferring unsigned integer [duplicate]

跟風遠走 提交于 2019-12-12 12:43:59
问题 This question already has answers here : Why are simple for loop expressions restricted to integer ranges? (3 answers) Closed 5 years ago . According to the MSDN documentation on the for ... to loop in F#: The type of the identifier is inferred from the type of the start and finish expressions. Types for these expressions must be 32-bit integers. But, with the code below, I get the following compile-time error: for bar = 0u to 5u do let baz : uint32 = bar () error FS0001: This expression was

Could not load file or assembly 'AWSSDK.Core On .net core in AWS Lambda

安稳与你 提交于 2019-12-12 12:35:44
问题 Using this template, I've been trying to get a Lambda function running. When it goes to execute a module containing open Amazon open Amazon.S3 it blows up with a "errorType": "FileNotFoundException", "errorMessage": "Could not load file or assembly 'AWSSDK.Core, Version=3.3.0.0, Culture=neutral, PublicKeyToken=885c28607f98e604'. The system cannot find the file specified.",` I've tried a nuget install of AWSSDK.Core to no avail. Errors in /Users/sanitized/aws_lambda/project.json Package AWSSDK

What is the correct way to return an “empty task” when implementing message handlers such as IExceptionHandler or IExceptionLogger in F#?

霸气de小男生 提交于 2019-12-12 12:31:47
问题 In C# when implementing these handlers I would do something similar to this, public class DefaultExceptionHandler : IExceptionHandler { public Task HandleAsync(ExceptionHandlerContext context, CancellationToken cancellationToken) { context.Result = new ErrorActionResult(context.Request, context.Exception); return Task.FromResult(0); } } When implementing the same interface in F# I did the following, type DefaultExceptionHandler() = let mapExceptionTypetoHttpStatusCode (ex:Exception) :

How to make a record implement an interface?

浪子不回头ぞ 提交于 2019-12-12 12:22:48
问题 If I have an interface: type IData = abstract member firstName: string abstract member lastName: string How do I define a record type that complies with this interface. I tried something like below: > type Data = { firstName: string; lastName: string } interface IData ;; Snippet.js(43,63): error FS0366: No implementation was given for 'abstract member IData.firstName : string'. Note that all interface members must be implemented and listed under an appropriate 'interface' declaration, e.g.

Closing a dialog with FSharp.ViewModule

只愿长相守 提交于 2019-12-12 12:15:54
问题 In my previous question "Enabling dialog OK button with FSharp.ViewModule", I got to the point where a dialog's OK button was enabled only when the validators for the dialog's fields were true, and ViewModule's IsValid property became true. But I ran into a couple more problems after that: 1) Clicking on the OK button didn't close the dialog, even if I set IsDefault="true" in XAML. 2) When the OK button is clicked, sometimes I want to do more checks than provided by the ViewModule validators

Converting OCaml to F#: Converting OCaml open_box and close_box to F#

对着背影说爱祢 提交于 2019-12-12 12:14:42
问题 I am converting several modules based on OCaml to F# and ran into the OCaml print formatting functions open_box and close_box from the OCaml format module. After reading about the concept of a printing box, it makes sense but seems like it needs a lot of work behind the scenes to implement. Is there an F# module that is functionally equivalent? If not, without having to convert portions of the OCaml format module, what are quick and simple replacement functions? EDIT Jack has a version as

Is it possible to pass parameters to F# modules?

耗尽温柔 提交于 2019-12-12 12:06:49
问题 I'm new to F# and learning the basics. I have two modules. A generic one for tree data structures called Tree : module Tree let rec getDescendants getChildren node = seq { yield node for child in getChildren node do yield! getDescendants getChildren child } let isLeaf getChildren node = Seq.isEmpty (getChildren node) let getLeaves getChildren node = getDescendants getChildren node |> Seq.filter (isLeaf getChildren) As you can see, all functions have a getChildren argument, which is a function

Cannot create list literal in F#

懵懂的女人 提交于 2019-12-12 12:02:05
问题 I have the following types type StatusCode = | OK = 200 | NoContent = 204 | MovedTemp = 301 | MovedPerm = 302 | SeeOther = 303 | NotModified = 304 | NotFound = 404 | ServerError = 500 [<Literal>] let NoBodyAllowedStatusCodes = [StatusCode.NoContent; StatusCode.NotModified] And I'm getting a compile-time error that says: This is not a valid constant expression or custom attribute value I can't really figure out what's wrong here. 回答1: In F#, and .NET in general, lists cannot be literals

What is the difference between mutable values and immutable value redefinition?

痴心易碎 提交于 2019-12-12 11:55:10
问题 I have read that values in F# are immutable. However, I have also come across the concept of redefining value definitions, which shadow the previous ones. How is this different from a mutable value ? I ask this not just as a theoretical construct, but also if there is any advice on when to use mutable values and when to redefine expressions instead; or if someone can point out that the latter is not idiomatic f#. Basic example of redefinition: let a = 1;; a;; //1 let a = 2;; a;; //2 Update 1:

Operating on an F# List of Union Types

孤街醉人 提交于 2019-12-12 11:34:17
问题 This is a continuation of my question at F# List of Union Types. Thanks to the helpful feedback, I was able to create a list of Report s, with Report being either Detail or Summary . Here's the data definition once more: module Data type Section = { Header: string; Lines: string list; Total: string } type Detail = { State: string; Divisions: string list; Sections: Section list } type Summary = { State: string; Office: string; Sections: Section list } type Report = Detail of Detail | Summary