f#

Why shouldn't I use F# asynchronous workflows for parallelism?

こ雲淡風輕ζ 提交于 2019-12-20 08:59:52
问题 I have been learning F# recently, being particularly interested in its ease of exploiting data parallelism. The data |> Array.map |> Async.Parallel |> Async.RunSynchronously idiom seems very easy to understand and straightforward to use and get real value from. So why is it that async is not really intended for this? Donald Syme himself says that PLINQ and Futures are probably a better choice. And other answers I've read here agree with that as well as recommending TPL. (PLINQ doesn't seem

Functional Reactive F# - Storing States in Games

蓝咒 提交于 2019-12-20 08:41:29
问题 I am a student currently learning about Functional Reactive paradigm using F#. It's radically new viewpoint for me. Yesterday I learned about creating a simple ping-pong game using this paradigm. The idea I grasp so far is : we think values as functions of time. On its pure form, it's stateless. However, I need to remember the position of the ball (or state). So I always pass the current position of the ball as the parameter of the global function. If we talk about slight more complex games,

recursive descent parser and functional programming

青春壹個敷衍的年華 提交于 2019-12-20 08:26:23
问题 So lately I have been working on writing a simple compiler to better understand compiler concepts. Being a diligent reader of stackoverfolow, it seems there is a consensus that writing a compiler in a functional language is easier than an imperative one. To this end I thought I would try and kill two birds and write a compiler in F# to both learn a functional language and write a compiler at the same time. I have been reading through the dragon book and decided to start with a recursive

Why is the F# version of this program 6x faster than the Haskell one?

╄→гoц情女王★ 提交于 2019-12-20 08:23:41
问题 Haskell version(1.03s): module Main where import qualified Data.Text as T import qualified Data.Text.IO as TIO import Control.Monad import Control.Applicative ((<$>)) import Data.Vector.Unboxed (Vector,(!)) import qualified Data.Vector.Unboxed as V solve :: Vector Int -> Int solve ar = V.foldl' go 0 ar' where ar' = V.zip ar (V.postscanr' max 0 ar) go sr (p,m) = sr + m - p main = do t <- fmap (read . T.unpack) TIO.getLine -- With Data.Text, the example finishes 15% faster. T.unlines . map (T

F# Pattern matching on a generic type Map

吃可爱长大的小学妹 提交于 2019-12-20 07:48:32
问题 This works : // sample objects let dctStrDbl = [("k1",1.0); ("k2",2.0)] |> Map.ofList let dctStrStr = [("k1","v1"); ("k2","v2")] |> Map.ofList let lstMisc = [1; 2; 3] let testStrDbl (odico : obj) : bool = match odico with | :? Map<string,double> as d -> true | _ -> false let testTrue = testStrDbl (box dctStrDbl) // this evaluates to true let testFalse = testStrStr (box dctStrStr) // this evaluates to false let testMiscFalse = testStrDbl (box lstMisc) // evaluates to false However I would like

How do I retrieve a value from a composite generic type?

ぃ、小莉子 提交于 2019-12-20 06:28:57
问题 How do I retrieve a value from a generic? Specifically, I am attempting the following: // Test let result = Validate goodInput;; // How to access record?? let request = getRequest result Here's the code: type Result<'TSuccess,'TFailure> = | Success of 'TSuccess | Failure of 'TFailure let bind nextFunction lastFunctionResult = match lastFunctionResult with | Success input -> nextFunction input | Failure f -> Failure f type Request = {name:string; email:string} let validate1 input = if input

How to get started using FSharp (F#) on OS X? [closed]

二次信任 提交于 2019-12-20 06:28:16
问题 Closed . This question needs to be more focused. It is not currently accepting answers. Want to improve this question? Update the question so it focuses on one problem only by editing this post. Closed 4 years ago . I know that mono exists, but just recently Microsoft released (I think) support for platforms other than windows [source]. If I wanted to start using FSharp on my OS X machine, how would I get started? Is that even possible yet? 回答1: At the moment, mono is the way to go - if you

F#, FParsec, and Calling a Stream Parser Recursively

家住魔仙堡 提交于 2019-12-20 04:51:47
问题 I'm developing a multi-part MIME parser using F# and FParsec. I'm developing iteratively, and so this is highly unrefined, brittle code--it only solves my first immediate problem. Red, Green, Refactor. I'm required to parse a stream rather than a string, which is really throwing me for a loop. Given that constraint, to the best of my understanding, I need to call a parser recursively. How to do that is beyond my ken, at least with the way I've proceeded thus far. namespace MultipartMIMEParser

How does fsi.ShowDeclarationValues work?

孤街醉人 提交于 2019-12-20 04:34:43
问题 According to the MSDN documentaion: When set to false, disables the display of declaration values in the output of the interactive session. However, the following sample interactive session seems to contradict that summary. > let x = 42;; val x : int = 42 > fsi.ShowDeclarationValues <- false;; val it : unit = () > let y = 42;; val y : int I was not expecting the last line above. Have I misunderstood something? Can anyone confirm if this is a bug? Thanks. 回答1: Daniel is correct - this disables

Passing a seq<float option> from F# to RProvider

冷暖自知 提交于 2019-12-20 04:22:54
问题 I want to be able to pass a sequence of option float to the RProvider in F# . If I have a sequence of floats with Some float and None , how can I get the None values into R with the RProvider ? I would have expected the None s would be equivalent to an NA value in R , but I can't get pass a seq<option float> to R. For example, with open System open RDotNet open RProvider open RProvider.graphics open RProvider.stats let optData4 = seq [Some 10.0; Some 9.0; Some 8.0; None; Some 6.0; Some 5.0;