f#

SQLite DateTime handling in SQLProvider

纵然是瞬间 提交于 2019-12-13 05:52:42
问题 How to use DateTime with SQLite via the SQLProvider type-provider? SQLite doesn't really have a date and time datatype (see Data types) and stores dates as text. I can pass a date string and query it, and get back a string. So this works, where Date1 in table3 was stored as a string: query { for r in table3 do select (r.Date1) } |> Seq.toList val it : string list = ["2016/06/09 0:00:00"; "2016/06/05 0:00:00"; "2016/06/04 0:00:00"; "2016/06/12 0:00:00"; "2016/06/10 0:00:00"; "2016/06/06 0:00

how to implement locking within function in multiple threads f#

天大地大妈咪最大 提交于 2019-12-13 05:04:55
问题 I created a mutable list called tickets that contains type Ticket. I also have a bookSeat function that imitates booking a seat.Since F# list type is immutable, my bookSeat function always returns a new, modified, copy of tickets list. open System open System.Threading type Ticket = {seat:int; customer:string} let mutable tickets = [for n in 1..10 -> {Ticket.seat = n; Ticket.customer = ""}] let bookSeat _ = Console.WriteLine("Enter seat number: ") let seatNo = int(Console.ReadLine()) Console

The mutable variable 'index' is used in an invalid way in seq {}?

有些话、适合烂在心里 提交于 2019-12-13 05:00:38
问题 In the following code, the compiler gets error on index <- index + 1 with error Error 3 The mutable variable 'index' is used in an invalid way. Mutable variables cannot be captured by closures. Consider eliminating this use of mutation or using a heap-allocated mutable reference cell via 'ref' and '!'. d:\Users....\Program.fs 11 22 ConsoleApplication2 However, it has been defined as mutable? let rec iterateTupleMemberTypes (tupleArgTypes: System.Type[]) (columnNames: string[]) startingIndex =

How to compare individual values in f# matrices?

丶灬走出姿态 提交于 2019-12-13 04:46:54
问题 I am trying to teach myself f#. For a program I am working on, I want to compare individual elements of 2 matrices, point wise. The matrices are both of size 1*N. The reason these are matrices is because they are the result of previous computations, performed using the standard F# PowerPack. I am happy to convert them to some other collection after these computations or use some other Matrix math library. What I need is a function that takes 2 matrices (which are essentially vectors) and

F# How to have a value's type determined by a match statement?

落花浮王杯 提交于 2019-12-13 04:46:10
问题 Here is my problem: let foo = match bar with | barConfig1 -> configType1(devices:DeviceEntities,DeviceStartIndex,inputStartIndex,outputStartIndex) | barConfig2 -> configType2(devices:DeviceEntities,DeviceStartIndex,inputStartIndex,outputStartIndex) | barConfig3 -> configType3(devices:DeviceEntities,DeviceStartIndex,inputStartIndex,outputStartIndex) | barConfig4 -> configType4(devices:DeviceEntities,DeviceStartIndex,inputStartIndex,outputStartIndex) I'd like to have the type of foo be

How do you sum up and average a Sequence?

泄露秘密 提交于 2019-12-13 04:41:30
问题 Say I have a coordinate (x, y) and its neighbors in a sequences of sequence (-1, 1)(0, 1)(1, 1)(-1, 0)(0, 0)(1, 0)(-1, -1)(0, -1)(1, -1) let n = [1 .. -1 .. -1] |> Seq.collect (fun j -> [-1 .. 1] |> Seq.map(fun i -> [i, j])) n |> Seq.iter(printf "%A") I'm trying to add x and y to each element in the sequence respectively Then get Color p = GetPixel(x+i, y+j) for every element in sequence, sum up and average out their R, G, B for (x,y) So we have 9 Red, 9 Green, 9 Blue to Ave(Red), Ave(Blue),

Function argument is null, even though a non-null argument is passed

末鹿安然 提交于 2019-12-13 04:35:24
问题 F# newbie here, and sorry for the bad title, I'm not sure how else to describe it. Very strange problem I'm having. Here's the relevant code snippet: let calcRelTime (item :(string * string * string)) = tSnd item |>DateTime.Parse |> fun x -> DateTime.Now - x |> fun y -> (floor y.TotalMinutes).ToString() |>makeTriple (tFst item) (tTrd item) //makeTriple switches y & z. How do I avoid having to do that? let rec getRelativeTime f (l :(string * string * string) list) = match l with | [] -> f | x

Calling IEnumerable.SelectMany

一曲冷凌霜 提交于 2019-12-13 04:33:56
问题 Given this: open System.Linq let iota n = [0..(n-1)] the following produces an error: [2; 3; 4].SelectMany(fun n -> iota n) Is there a way to pass function values to SelectMany ? 回答1: You need to cast the result to a seq<int> : [2; 3; 4].SelectMany(fun n -> iota n :> int seq) alternatively you could use List.collect : [2; 3; 4] |> List.collect iota 来源: https://stackoverflow.com/questions/23315615/calling-ienumerable-selectmany

Abstracting over Collection Types

纵饮孤独 提交于 2019-12-13 03:49:15
问题 Is there a possibility of writing functions which are generic in respect to collection types they support other than using the seq module? The goal is, not having to resort to copy and paste when adding new collection functions. 回答1: The seq<'T> type is the primary way of writing computations that work for any collections in F#. There are a few ways you can work with the type: You can use functions from the Seq module (such as Seq.filter , Seq.windowed etc.) You can use sequence

Polymorphism with Generics and common fields

时光怂恿深爱的人放手 提交于 2019-12-13 03:36:06
问题 Had this question answered and is somewhat similar but this question requires using Generics while enforcing parameter type to have some common fields. type Document = { Name: string Version: string } let inline requestData<'t> (document: 't) = Console.WriteLine(document.Name) Console.WriteLine(document.Version) Test requestData<Document>({Name = "test"; Version="259723983"}) The error I'm getting is Lookup on object of indeterminate type based on information prior to this program point. A