Logical negation operator in F#? (!-equivalent)
According to “Foundations of F#”, page 61: F# uses a function called not for Boolean “not” operations.
According to “Foundations of F#”, page 61: F# uses a function called not for Boolean “not” operations.
Say you have some arbitrary data entity out in the world. For this example, let’s say it’s a spreadsheet. Let’s also say you have some way to get/infer schema/metadata for that data – that is, you can know types (e.g. double versus string) and relationships (e.g. this column means ‘salary’) and metadata (e.g. this sheet … Read more
‘let rec… and…’ is the syntax you seek. let rec F() = G() and G() = F() See also Adventures in F# Co-Recursion.
I would just use the .NET Stopwatch class. let stopWatch = System.Diagnostics.Stopwatch.StartNew() … stopWatch.Stop() printfn “%f” stopWatch.Elapsed.TotalMilliseconds
Building on Brian’s and Stephen’s answers, here’s some complete code: module NumericLiteralG = let inline FromZero() = LanguagePrimitives.GenericZero let inline FromOne() = LanguagePrimitives.GenericOne let inline FromInt32 (n:int) = let one : ^a = FromOne() let zero : ^a = FromZero() let n_incr = if n > 0 then 1 else -1 let g_incr = if … Read more
When working with higher-order functions (i.e. functions that return other functions and/or take other functions as parameters), you always have to provide something as parameter, but there isn’t always an actual data transformation that you’d want to apply. For example, the function Seq.collect flattens a sequence of sequences, and takes a function that returns the … Read more
[<System.Runtime.CompilerServices.Extension>] module Methods = [<System.Runtime.CompilerServices.Extension>] let Exists(opt : string option) = match opt with | Some _ -> true | None -> false This method could be used in C# only by adding the namespace (using using) to the file where it will be used. if (p2.Description.Exists()) { …} Here is a link to the … Read more
I have looked at F#, doing low level tutorials, so my knowledge of it is very limited. However, it was apparent to me that its style was essentially functional, with OO being more like an add on — much more of an ADT + module system than true OO. The feeling I get can be … Read more
I think @kvb gives a good overview of some of the technical difficulties. I agree type inference would be problematic – you would be basically limited to using provider generated types locally, similarly to anonymous types. I think C# might come with something similar in Roslyn, but I doubt it will be as elegantly and … Read more
Apparently not: C:\temp\Tim>type 1.fs 2.fs 1.fs #light module Module let sayHello1 = printfn “Hello, ” 2.fs #light module Module let sayHello2 = printfn “world!” C:\temp\Tim>fsc 1.fs 2.fs Microsoft F# Compiler, (c) Microsoft Corporation, All Rights Reserved F# Version 1.9.6.2, compiling for .NET Framework Version v2.0.50727 2.fs(2,1): error FS0191: An implementation of the file or module … Read more