F# type providers, how do they work

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

How to write a function for generic numbers?

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

What’s the purpose of `id` function in the FSharp.Core?

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

F# extension methods in C#

[<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

Split F# modules across multiple files

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

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)