F# interactive shell (fsi) tutorial?
Use #help;; for help, #quit;; to quit.
Use #help;; for help, #quit;; to quit.
You can use ContinueWith: let awaitTask (t: Task) = t.ContinueWith (fun t -> ()) |> Async.AwaitTask Or AwaitIAsyncResult with infinite timeout: let awaitTask (t: Task) = t |> Async.AwaitIAsyncResult |> Async.Ignore
In your example, x is an immutable value that is assigned during runtime (but NOT evaluated lazily), whereas y is assigned during compiletime. As an example, let myDLL = “foo.dll” [<DllImport(myDLL, CallingConvention = CallingConvention.Cdecl)>] extern void HelloWorld() will not work, because DllImport is an attribute and needs to know the value of myDLL during compilation. … Read more
The following is an example of multiple columns being used for grouping in c# and converted to f# (overly paranoid management has made me rename everything, but I believe I have been consistent): (TheDatabase was generated by SqlMetal, GetSummedValuesResult is a F# record type) c# public static class Reports { public static IReadOnlyList<GetSummedValuesResult> GetSummedValues(TheDatabase db, … Read more
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
It looks like the Right Way to do this in F# 2.0 is by using the StructuredFormatDisplay attribute, for example: [<StructuredFormatDisplay(“hello {a}”)>] type myType = {a: int} In this example, instead of the default {a = 42;}, you would get hello 42. This works the same way for object, record, and union types. And although … Read more