f#

Deserializing to enum option in F#

北慕城南 提交于 2019-12-13 20:13:31
问题 A couple days ago, I posted a question about deserialization with enums in F#. The question is here: Deserialization in F# vs. C# The answer pointed to some code written by Isaac Abraham, at: https://gist.github.com/isaacabraham/ba679f285bfd15d2f53e However I am facing another problem: If the object to deserialize to has an object of type 'enum option', the deserialization will fail, whereas it'll work if the type is just 'enum'. A minimal example: type TestType = | A = 0 | B = 1 type

Controlling async actions that might conflict in F#

Deadly 提交于 2019-12-13 19:47:05
问题 I have many actions ( Async<T> list ) to perform in F#. I can execute most of these actions in parallel, but some might conflict due to file locks etc. For each action, I can generate a "key" ( int ) that determines if the actions might conflict: If action a has key i and action b has key j and i = j , then a and b might conflict. They must be executed serially. If action a has key i and action b has key j and i <> j , then a and b will never conflict. They may be executed in parallel. I

In F#, How can I attach metadata to discriminated union values?

自闭症网瘾萝莉.ら 提交于 2019-12-13 18:44:38
问题 I want to create something that's kind of like an enum with an F# record type for a value instead of an int. For example, if I've got the union: type BologneseIngredients = | Spaghetti | Tomatoes | MincedBeef | GrandmasSecretIngredient I know that spaghetti is always 30cm long and tomatoes are always red. What I could do is have a 'get metadata' function: let getMetadata = function | Spaghetti -> { length: 30.0<cm> } | Tomatoes -> { colour: Color.Red } | _ -> { } but I'd really like to keep

Is there an existing pattern to generate a list of the applications of a function to every combination of the items in two lists?

与世无争的帅哥 提交于 2019-12-13 18:42:31
问题 I'm just getting into functional programming and i'm in the "try out some non-trivial examples and ask others if I'm doing it wrong" phase. I'm following Don Syme's F# Tutorial and have decided to take a stab at the blackjack exercise at the end of Part II with a twist: he suggests treating Ace as 11 for simplicity's sake, but I decided to ignore that recommendation. The way I'm handling it is by giving each card rank a list of possible values and building up a list of possible hand values

Type reference error using F# interactive

谁都会走 提交于 2019-12-13 17:42:17
问题 I have a solution consisting of 2 projects: Utilities - This project contains type MyMatlab and references a COM (TLP) reference Matlab Application (Version 7.11) Type Library LBM - This project contains function displayMyMatlab which uses the MyMatlab type from the Utilities project and thus this project references Utilities I create a fsx file containing: #r @".\bin\Release\LBM.dll" #r @".\bin\Release\Utilities.dll" LBM.displayMyMatlab() and I get following error: Microsoft (R) F# 2.0

Reading value from XML file Throws an error - FAKE F#MAKE

左心房为你撑大大i 提交于 2019-12-13 17:21:01
问题 I am trying to read value from XML file from FAKE , But I am getting an error i.e. .fsx(9,16) : eror FS000: Incomplete structurd construct at or before this point in expression. Expected '->' or other token. Below is my code , I am using XMLHelper.XMLRead to read values from xml file . #r "./packages/FAKE/tools/FakeLib.dll" open Fake open Fake.XMLHelper Target "BuildMain" (fun _ -> for s in XMLHelper.XMLRead true "D:/test/Version.Config" "/version/major/minor" trace s) "BuildMain"

How can I map over a record using interfaces

回眸只為那壹抹淺笑 提交于 2019-12-13 17:07:59
问题 given the following types and value type Item<'a, 'b> = Item of 'a * 'b type X<'a, 'b> = { y: Item<'a, int> z: Item<'b, bool> } let a = { y = Item (false, 2); z = Item (1, true) } I want to create a generic mapping function tmap: X<'a, 'b> -> X<'x, 'y> using interfaces and object expressions. My approach so far was type ITransform<'a, 'b, 'x, 'y> = abstract Apply : Item<'a,'b> -> Item<'x,'y> let inline tmap (f:ITransform<_,_,_,_>) ({y = yi; z = zi}) = { y = f.Apply yi z = f.Apply zi } However

Working with missing values in Deedle Time Series in F# (2)

倾然丶 夕夏残阳落幕 提交于 2019-12-13 16:32:53
问题 This question is related to Working with missing values in Deedle Time Series in F# (1) Suppose i have a Series<'K,'T opt> with some missing values For example i have obtained a series series4;; val it : Series<int,int opt> = 1 -> 1 2 -> 2 3 -> 3 4 -> <missing> I could have got it this way: let series1 = Series.ofObservations [(1,1);(2,2);(3,3)] let series2 = Series.ofObservations [(1,2);(2,2);(3,1);(4,4)] let series3 = series1.Zip(series2,JoinKind.Outer);; let series4 = series3 |> Series

nested runtime coercion for a Nullable double

萝らか妹 提交于 2019-12-13 16:05:31
问题 Let's say I have a value defined as a sort of commission formula let address_commission = 1.0 // minimal simplified example and I want to apply the above said commission to an amount I'm reading from the DB (the code is from a window WCF service I have in production) let address_commission = 1.0 // minimal simplified example new Model.ClaimModel( //RequestRow = i, recounting Code = (row.["claim_code"] :?> string), EvtDate = (row.["event_date"] :?> DateTime), // skipping lines... Amount = (row

F# mutual recursion between modules

自古美人都是妖i 提交于 2019-12-13 15:23:49
问题 For recursion in F#, existing documentation is clear about how to do it in the special case where it's just one function calling itself, or a group of physically adjacent functions calling each other. But in the general case where a group of functions in different modules need to call each other, how do you do it? 回答1: I don't think there is a way to achieve this in F#. It is usually possible to structure the application in a way that doesn't require this, so perhaps if you described your