f#

F#/“Accelerator v2” DFT algorithm implementation probably incorrect

强颜欢笑 提交于 2019-12-06 04:41:36
I'm trying to experiment with software defined radio concepts. From this article I've tried to implement a GPU-parallelism Discrete Fourier Transform. I'm pretty sure I could pre-calculate 90 degrees of the sin(i) cos(i) and then just flip and repeat rather than what I'm doing in this code and that that would speed it up. But so far, I don't even think I'm getting correct answers. An all-zeros input gives a 0 result as I'd expect, but all 0.5 as inputs gives 78.9985886f (I'd expect a 0 result in this case too). Basically, I'm just generally confused. I don't have any good input data and I don

F# quotations: variable may escape scope

喜你入骨 提交于 2019-12-06 04:41:31
问题 I have this bit of code: let rec h n z = if n = 0 then z else <@ (fun x -> %(h (n - 1) <@ x + %z @>)) n @> converted from a MetaOcaml example in http://www.cs.rice.edu/~taha/publications/journal/dspg04a.pdf In the paper there is explained that the above example will yield the following with the parameters 3 and .<1>. (in MetaOcaml notation): .<(fun x_1 -> (fun x_2 -> (fun x_3 -> x_3 + (x_2 + (x_1 + 1))) 1) 2) 3>. As you can see the x ´s gets replaced by x_1 , x_2 etc. because the x would

Dynamic SQL queries with F# 3.0?

女生的网名这么多〃 提交于 2019-12-06 04:33:23
问题 I have tried to use FLINQ but it is rather out of date with F# 3.0 beta. Can someone give me some pointers on how to create dynamic SQL queries in F#? 回答1: In F# 3.0, the query is quoted automatically and so you cannot use quotation splicing (the <@ foo %bar @> syntax) that makes composing queries possible. Most of the things that you could write by composing queries using splicing can still be done in the "usual LINQ way" by creating a new query from the previous source and adding i.e.

Drag and Drop in Silverlight with F# and Asynchronous Workflows

白昼怎懂夜的黑 提交于 2019-12-06 04:22:58
I'm trying to implement drag and drop in Silverlight using F# and asynchronous workflows. I'm simply trying to drag around a rectangle on the canvas, using two loops for the the two states (waiting and dragging), an idea I got from Tomas Petricek's book "Real-world Functional Programming", but I ran into a problem: Unlike WPF or WinForms, Silverlight's MouseEventArgs do not carry information about the button state, so I can't return from the drag-loop by checking if the left mouse button is no longer pressed. I only managed to solve this by introducing a mutable flag. Would anyone have a

“Merging” Discriminated Unions in F#?

自作多情 提交于 2019-12-06 04:14:49
Following on from this question , I am having an issue combining differently typed Result types together. (what follows is a contrived example, not real code) Suppose I have a function that reads a file: type ReadFileError = | FileNotFound of string let readFile (path : string) : Result<string, ReadFileError> = // --- 8< --- And a function that parses it somehow: type JsonParseError = | InvalidStructure of string let parseJson (content : string) : Result<Json, JsonParseError> = // --- 8< --- Now I can combine these to create a function that reads and parses a file: type ReadJsonError = |

How do I print an entire list in F#?

白昼怎懂夜的黑 提交于 2019-12-06 04:11:40
问题 When I use Console.WriteLine to print a list, it defaults to only showing the first three elements. How do I get it to print the entire contents of the list? 回答1: You can use the %A format specifier along with printf to get a 'beautified' list printout, but like Console.WriteLine (which calls .ToString()) on the object, it will not necessarily show all the elements. To get them all, iterate over the whole list. The code below shows a few different alternatives. let smallList = [1; 2; 3; 4]

A MailboxProcessor that operates with a LIFO logic

女生的网名这么多〃 提交于 2019-12-06 04:01:11
问题 I am learning about F# agents ( MailboxProcessor ). I am dealing with a rather unconventional problem. I have one agent ( dataSource ) which is a source of streaming data. The data has to be processed by an array of agents ( dataProcessor ). We can consider dataProcessor as some sort of tracking device. Data may flow in faster than the speed with which the dataProcessor may be able to process its input. It is OK to have some delay. However, I have to ensure that the agent stays on top of its

How do I write an enumeration in F# without explicitly assigning number literals?

非 Y 不嫁゛ 提交于 2019-12-06 03:49:45
问题 I have an enumeration in F#, like this: type Creature = | SmallCreature = 0 | MediumCreature = 1 | GiantCreature = 2 | HumongousCreature = 3 | CreatureOfNondescriptSize = 4 I do not like manually typing out numbers, and I want to easily insert more items in the enumeration later without having to shift the numbers. I tried this type Creature = | SmallCreature | MediumCreature | GiantCreature | HumongousCreature | CreatureOfNondescriptSize but it caused an error The type 'Creature' is not a

Awaiting an F# async task inside an akka.net actor{} expression

这一生的挚爱 提交于 2019-12-06 03:44:27
问题 Is it possible to wait (without blocking) on an Async<'t> within an Akka.Net actor computation? I want to achieve something similar to the following. actor { let! msg = mailbox.Receive() match msg with | Foo -> let! x = async.Return "testing 123" // Some async function, return just an example () // Do something with result } 回答1: No you can't use async / await or any variant thereof inside an actor's mailbox and get safe results. Each actor maintains its own context, which includes important

Functional O(1) append and O(n) iteration from first element list data structure

左心房为你撑大大i 提交于 2019-12-06 03:25:03
问题 I'm looking for a functional data structure that supports the following operations: Append, O(1) In order iteration, O(n) A normal functional linked list only supports O(n) append, while I could use a normal LL and then reverse it, the reverse operation would be O(n) also which (partially) negates the O(1) cons operation. 回答1: You can use John Hughes's constant-time append lists, which seem nowadays to be called DList . The representation is a function from lists to lists: the empty list is