spot7.org logo
Home PHP C# C++ Android Java Javascript Python IOS SQL HTML Categories
  Home » F# » Page 1
Why can't F# infer the type in this case?
As hinted by @ildjarn, Cell is a generic type and the compiler wants to know the type 'T when calling the static member. // Two ways to fix the compiler warning let x = Cell<int>.CreateInt 123 let y = StringCell.CreateString "testing" A way to avoid specifying 'T is to move the create functions into a module. type Cell<'T> = { slot: 'T } type IntCell = Cell<int> type StringCe

Categories : F#

Newtonsoft cannnot deserialize an empty F# sequence?
I guess the answer is, Newtonsoft.Json doesn't fully support F# types. But F# doesn't make supporting them particularly easy. For instance, an empty seq defined with Seq.empty is not just an IEnumerable<T>, it's a particular enumerable implementation EmptyEnumerable<T>, and this seems to throw off serialization - most likely because there's no appropriate constructor on it. From the

Categories : F#

Giving relative path of project in F#
It would seem like you could use conditional preprocessor directives to help you here. [<Literal>] let resolutionFolder = #if DEBUG @"D:<myprojectdirectory><projectname>packagesNpgsql.2.2.2lib et45" #else @"..sqlproviderpackagesNpgsql.2.2.2lib et45" #endif

Categories : F#

stack overflow in F# compiler running under mono
This is too long for a comment, but the error is triggered by this bit of code from generated.fs (in that commenting it out stops the stack overflow - there is an error later once this is commented out) (from line 6496-6506): [<DllImport( llvmAssemblyName, EntryPoint="LLVMRunFunction", CallingConvention=CallingConvention.Cdecl, CharSet=CharSet.A

Categories : F#

Pass function as a parameter and overload it
You're probably thinking of passing a method group as an argument to GetTime, and then having the compiler decide which overload of the method group to call. That's not possible with any .NET compiler. Method groups are used for code analysis by compilers and tools such as ReSharper, but they are not something that actually exists at runtime.

Categories : F#

Constraint produces "This construct causes code to be less generic..."
Calling the getter is weird. You can do it explicitly like this: let inline showMeABar item = (^Item : (member Bar : string) item) Record labels have the weird (but useful) property that their usage with dot-notation is a hint to type inference. Hence the strange error message.

Categories : F#

Why the difference between type signatures of the same F# function in module vs class?
I can only think of a few times you'd ever need to worry about the distinction between A -> B and (A -> B) (see the F# spec's section on signature conformance for related commentary): When you want to implement a module signature, only a syntactic function can serve as the implementation of something with the signature A -> B, while either a syntactic function or any other function valu

Categories : F#

How to pass the type generated by F#'s SqlDataProvider as a parameter to function
Just figured it out, simpler than I thought, just the VS tooltips are a bit misleading. The correct sample looks like: type MyDb = SqlDataProvider< @"Server=myServerDatabase=myDatabase;Trusted_Connection=True;", Common.DatabaseProviderTypes.MSSQLSERVER> let ctx1 = RfqDb.GetDataContext("Server=myServerDatabase=myDatabase;Trusted_Connection=True;") let ctx2 = Rf

Categories : F#

Why does this point-free F# function behave differently from the non-point-free version?
getValFromMapPartial is a true syntactic function. Its signature is val getValFromMapPartial : key:string -> int. Whenever it is called, it uses the current value of someMap. That's why it works in your example; it accesses the version of someMap who has an entry. On the other hand, getValFromMapPartialAndTacit is a lambda-computing function. Its signature is val getValFromMapPartialAndTacit :

Categories : F#

Implicit conversion from char to char[] in F#?
String.Split doesn't quite take a char[] as an argument. It actually takes a params char[]. As a result, the compiler does some magic and the call is possible with just a single char.

Categories : F#

Proper F# type annotation for MathNet.Numerics.LinearAlgebra.vector
This vector type is generic; the generic argument indicates the type of each component of the vector. A type annotation must at least indicate the number of generic arguments, e.g. Vector<_> for any such vector, or Vector<float> for the exact type used in the question. In other words, Vector<_> and Vector are unrelated types to the compiler. The annotation is supposed to denote

Categories : F#

F# How Async<'T> cancellation works?
There are two things about the question: First, when a cancellation happens in F#, the AwaitTask does not return null, but instead, the task throws OperationCanceledException exception. So, you do not get back None value, but instead, you get an exception (and then F# also runs your final block). The confusing thing is that cancellation is a special kind of exception that cannot be handled in u

Categories : F#

Base 2 logarithm in F#
You could simply use the fact that the "a-logarithm of b" = ln(b) / ln(a), that is, the 2-logarithm of x is ln(x) / ln(2). log2(8) = ln(8) / ln(2) = 3 log2(32) = ln(32) / ln(2) = 5 ...where ln is either the natural logarithm or log10, either logarithm will work.

Categories : F#

dotCover in FAKE
Finally found an answer to my question: !! (buildDir @@ buildMode @@ "/*.Unit.Tests.dll") |> DotCoverNUnit (fun dotCoverOptions -> { dotCoverOptions with Output = artifactsDir @@ "NUnitDotCover.snapshot" }) (fun nUnitOptions -> { nUnitOptions with DisableShadowCopy = true })

Categories : F#

wrapping printf and still take parameters
First of all, your cprintf function is perfectly fine and you can use it with variable number of arguments. The problem is only with the cprintfn function: cprintf System.ConsoleColor.Red "%s %d" "hi" 42 The problem is that when you're defining a function that uses formatting string, you always need to use partial application. That is your function has to be of the form: let myprintf fmt =

Categories : F#


Recently Add
String.length and concatenated strings
Why can't F# infer the type in this case?
Newtonsoft cannnot deserialize an empty F# sequence?
Giving relative path of project in F#
stack overflow in F# compiler running under mono
Pass function as a parameter and overload it
Constraint produces "This construct causes code to be less generic..."
Why the difference between type signatures of the same F# function in module vs class?
How to pass the type generated by F#'s SqlDataProvider as a parameter to function
Why does this point-free F# function behave differently from the non-point-free version?
Implicit conversion from char to char[] in F#?
Proper F# type annotation for MathNet.Numerics.LinearAlgebra.vector
F# How Async<'T> cancellation works?
Base 2 logarithm in F#
dotCover in FAKE
wrapping printf and still take parameters
© Copyright 2017 spot7.org Publishing Limited. All rights reserved.