f#

Understanding F# value restriction

随声附和 提交于 2021-02-10 07:02:22
问题 I'm learning F#. I'm here because I had something hard to understand about value restriction. Here are the examples from the book I'm studying with. let mapFirst = List.map fst Since I had learned FP with haskell, I was pretty sure that this code would be well compiled, but it was not the case. It resulted error FS0030 (Sorry that I can't copy-paste fsi error message, since it was written in korean). Instead, I had to provide an explicit argument like: let mapFirst inp = List.map fst inp //

How to use F# 4.7 on Mac?

生来就可爱ヽ(ⅴ<●) 提交于 2021-02-10 05:29:06
问题 With the latest VS for mac installed (8.5 preview) and the latest net core sdk (3.1.200) F# 4.7 should be supported. When I run the dotnet fsi, indeed language features are supported and the FSI shows F# 4.7 as the F# version. In VS for mac, in the preferences settings the exact command: /usr/local/share/dotnet/dotnet fsi is the path to the F# compiler. However, when creating a new fix file and trying F# language features, it doesn’t work and the FSI in VS for mac doesn’t compile the code.

How to use F# 4.7 on Mac?

丶灬走出姿态 提交于 2021-02-10 05:28:14
问题 With the latest VS for mac installed (8.5 preview) and the latest net core sdk (3.1.200) F# 4.7 should be supported. When I run the dotnet fsi, indeed language features are supported and the FSI shows F# 4.7 as the F# version. In VS for mac, in the preferences settings the exact command: /usr/local/share/dotnet/dotnet fsi is the path to the F# compiler. However, when creating a new fix file and trying F# language features, it doesn’t work and the FSI in VS for mac doesn’t compile the code.

How do you return a null Tuple from f# to c#? [duplicate]

*爱你&永不变心* 提交于 2021-02-10 05:04:38
问题 This question already has answers here : F# how to return have value a tuple or null (3 answers) Closed 24 days ago . I have this type-correct C# function: static System.Tuple<int,int> f(int n) { switch (n) { case 0: return null; default: return System.Tuple.Create(n,n+1); } } I try to re-implement it in F#: let f = function | 0 -> null | n -> System.Tuple.Create(n, n+1) Type-checker disagrees, though: error FS0001: The type '('a * 'b)' does not have 'null' as a proper value. How do I re

Does MailboxProcessor just duplicate IObservable?

限于喜欢 提交于 2021-02-09 10:50:49
问题 I want to process to types of a message Add x makes program remember number x Print makes it print all remembered numbers Why would I write this: open System type Message = | Add of int | Print let mailbox = new MailboxProcessor<Message>(fun inbox -> let rec loop history = async{ let! msg=inbox.Receive() match msg with | Add x -> return! loop(history + x.ToString()+" ") | Print -> printfn "%s" history return! loop(history) } loop "" ) [<EntryPoint>] let main argv = mailbox.Start() mailbox

Constructing and deconstructing records

谁都会走 提交于 2021-02-08 20:50:15
问题 The msdn page documenting Records (F#) details record expressions for record construction and record patterns for deconstruction, the latter without naming them as such. Here's an example which uses both techniques for an arithmetic operator: // Simple two-dimensional generic vector defintion type 'a UV = { U : 'a; V : 'a } static member inline (+) ({ U = au; V = av }, { U = bu; V = bv }) = { U = au + bu; V = av + bv } This appears unwieldy and not very readable. For deconstruction, there are

Calling C# async method from F# results in a deadlock

六月ゝ 毕业季﹏ 提交于 2021-02-08 15:09:56
问题 I have a set of F# scripts that call various libraries that we have created, many of them exposing asynchronous methods originally written in C#. Recently I found out the scripts stopped working (I think it's about half a year since I used them last time and they worked back then). I was trying to isolate the problem and came up with the following code that reproduces it: First, let's consider a library containing the following C# class: public class AsyncClass { public async Task<string>

Explicit type parameters in let bindings in classes

给你一囗甜甜゛ 提交于 2021-02-08 13:14:35
问题 When I try to create some class like type MyType () = let func<'T> () = () The compiler says that there's an error: Explicit type parameters may only be used on module or member bindings But the MSDN says: A let binding at the module level, in a type, or in a computation expression can have explicit type parameters. A let binding in an expression, such as within a function definition, cannot have type parameters. Why documentation and compiler say different things? 回答1: This appears to be a

Explicit type parameters in let bindings in classes

我只是一个虾纸丫 提交于 2021-02-08 13:14:10
问题 When I try to create some class like type MyType () = let func<'T> () = () The compiler says that there's an error: Explicit type parameters may only be used on module or member bindings But the MSDN says: A let binding at the module level, in a type, or in a computation expression can have explicit type parameters. A let binding in an expression, such as within a function definition, cannot have type parameters. Why documentation and compiler say different things? 回答1: This appears to be a

Explicit type parameters in let bindings in classes

半世苍凉 提交于 2021-02-08 13:13:16
问题 When I try to create some class like type MyType () = let func<'T> () = () The compiler says that there's an error: Explicit type parameters may only be used on module or member bindings But the MSDN says: A let binding at the module level, in a type, or in a computation expression can have explicit type parameters. A let binding in an expression, such as within a function definition, cannot have type parameters. Why documentation and compiler say different things? 回答1: This appears to be a