f#

Stack overflow exception when using pipes in tail-recursive function

余生长醉 提交于 2020-01-03 07:33:07
问题 I have a naive implementation of a gameloop let gameLoop gamestate = let rec innerLoop prev gamestate = let now = getTicks() let delta = now - prev gamestate |> readInput delta |> update delta |> render delta |> innerLoop delta innerLoop 0L gamestate This implementation throws a stackoverflowexception. In my mind this should be tail recursive. I could make a work around like this let gameLoop gamestate = let rec innerLoop prev gamestate = let now = getTicks() let delta = now - prev let

F#: Quotation with type definition?

安稳与你 提交于 2020-01-03 07:31:09
问题 I'm playing around with quotations and I can't see an expression pattern for type definitions. Is there really not one, or am I missing something? <@@ type MyType (name:string) = member x.Name = name @@> Gives "Unexpected keyword 'type' in quotation literal." 回答1: You can't. You can only quote code, that is to say, any valid F# expression. Type definitions are not considered as code, but definitions. What you might want to do is put ReflectedDefinition attribute on a type members: type MyType

What is the F# syntax for “not equal to”?

亡梦爱人 提交于 2020-01-03 07:19:11
问题 In C code, it would be like this: if (c != 0) { //some code ...} what about in F#? 回答1: From MSDN's page on F# arithmetic operators, it looks like you want x <> 0 . 回答2: I think what you're looking for is the F# not operator or the <> operator for inequality. 回答3: In addition to the other answers, you can also use pattern matching: match c with | 0 -> () //do nothing | _ -> ... //do something 回答4: <> is used for inequality (1<>2) 来源: https://stackoverflow.com/questions/9130181/what-is-the-f

Cannot add reference from C# PCL to F# PCL (VS 2015 Update 1)

混江龙づ霸主 提交于 2020-01-03 06:48:07
问题 I have problems creating F# portable project which than should be referenced from C# portable project. When adding such reference, the following message appears: Unable to add a reference to 'PortableLibrary1'. Portable Library projects can only reference other Portable Library projects and assemblies. The problem is easily reproduced using latest Visual Studio 2015 Update 1 (version 14.0.24720.00). I also have Xamarin installed. I can reproduce the problem using any kind of C# portable

F# canopy - how to use LiveHtmlReporter?

北城余情 提交于 2020-01-03 04:52:45
问题 I am trying to get F# and canopy to log tests in html files. So here it says that all I need to do is: open configuration open reporters reporter <- new LiveHtmlReporter() :> IReporter This didn't work for me. I managed to start the LiveHtmlReporter by using Chrome to start it. Now I am struggling to make it save the reports after tests are finished. When I try to use: reporter <- new LiveHtmlReporter(Chrome, "C:\\") :> IReporter let liveHtmlReporter = reporter :?> LiveHtmlReporter

Can I ignore error without using try catch()?

痴心易碎 提交于 2020-01-02 14:34:49
问题 So I want to now if that possible for .NET languages to ignore error without using try catch construction ? I can ignore warring with #nowarring 40 for example, can I ignore error ? Why I want it ? simply wanted to call system pause with this way open System.Runtime.InteropServices [<DllImport(@"msvcrt.dll")>] extern void system(string str) system "pause" but got Error message unbalanced stack. This is probably because the managed PInvoke signature does not match the unmanaged target

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

十年热恋 提交于 2020-01-02 12:46:09
问题 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

F# functional style approach much slower

僤鯓⒐⒋嵵緔 提交于 2020-01-02 12:16:13
问题 Trying to learn F#, by solving some programming puzzles. I don't want to add too many details about the problem as I don't want to spoil the fun for others. Basically, the issue is to find all 4-uples { (i,j,k,l) | i ^ j ^ k ^ l != 0 } with no repetition (eg., (1,1,1,2) and (1,1,2,1) are the same and should be counted just once). I have found a O(n^3) approach which works, please see countImperative(a,b,c,d) below. But I also tried to refactor the code as to get rid of the nested for loops.

Performance issue with reading integers from a binary file at specific locations in F#

我们两清 提交于 2020-01-02 10:13:48
问题 This morning I asked here why my Python code was (a lot) slower then my F# version but I'm wondering whether the F# version can be made faster. Any ideas how I could create a faster version of the below code that reads a sorted list of unique indexes from a binary file with 32-bit integers? Note that I tried 2 approaches, one based on a BinaryReader, the other one based on MemoryMappedFile (and some more on Github). module SimpleRead let readValue (reader:BinaryReader) cellIndex = // set

Using F# JsonProvider within a portable class library fails

风格不统一 提交于 2020-01-02 07:30:56
问题 I'm trying to use the JsonProvider and I'm getting the following error when I call a function on it: System.TypeInitializationException was unhandled Message: An unhandled exception of type 'System.TypeInitializationException' occurred in PortableLibrary1.dll Additional information: The type initializer for '<StartupCode$PortableLibrary1>.$PortableLibrary1' threw an exception. I have a basic console application as follows: module Pinit = open FSharp.Data type JsonT = JsonProvider<"""..\myFile