how does [] differ from other constants in F#

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

groupby multiple columns in a F# 3.0 query

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

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

How do I customize output of a custom type using printf?

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

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