f#

Http request ending as bad request due to Encoding and Escape character issues

假如想象 提交于 2019-12-11 11:06:09
问题 Note: Code is in F# but tagging C# because it's a general encoding and escape character issue across .net while converting from object to json , please look at the output at the bottom of the page. Following request is ending up a bad request, please have a look at any discrepancies especially in the Encoding.Default.GetString and then encoding back into System.Text.Encoding.ASCII.GetBytes especially. Context: An object is serialized and written to the body of the PUT request and is ended up

How to use recursive of list, functionally

二次信任 提交于 2019-12-11 11:00:11
问题 Say i have a list containing maps: let mone = Map.ofList["1", "cat"; "2", "tiger"; "3", "lynx"] let mtwo= Map.ofList["1", "dog"; "2", "wolf"; "3", "puppy"] let mthree= Map.ofList["1", "bird"; "2", "chicken"; "3", "pigeon"] let mlist = [mone; mtwo; mthree] how can i use recursive to display one map at a time, rather then displaying all the maps? for example, displaying first element then ending iteration, to move onto something else, then displaying the second element etc. 来源: https:/

Issues Creating Records with FsCheck

喜你入骨 提交于 2019-12-11 10:58:13
问题 This question is a follow-up to an earlier question on using FsCheck to generate records. The original question was answered with a well composed example solution. However, prior to the answer being shared, I attempted to create a generator which is included below. Unfortunately, the generated records of type QueryRequest = {Symbol: string; StartDate: DateTime; EndDate: DateTime} have the following issues: Missing symbol Start dates earlier than January 1, 2000 End dates later than January 1,

Using FsCheck to Generate Records

元气小坏坏 提交于 2019-12-11 10:57:39
问题 I'd like to use FsCheck (with XUnit) to create records of type: type QueryRequest = {Symbol: string; StartDate: DateTime; EndDate: DateTime} where Symbol is limited to 3 options - ORCL , IBM , AAPL , and StartDate and EndDate are limited to the range between January 1, 2000 and January 1, 2019 . However, I'm unclear as to how proceed. Should I use Arb.generate<T> or Arb.Default or some other utility upon which to base the generation and shrinking of the test cases? Update 1 Follow-on question

Type x is less accessible than the value

蓝咒 提交于 2019-12-11 10:48:34
问题 Here's an abstraction of my code: module RootModule module private SubModule = // I want everything in this module to be inaccessible from outside the file let getLength s = String.Length s type MyType (s: string) = let _str = s member this.GetStringLength = getLength _str // for sake of simplicity, a bogus method let myExternalValue = new SubModule.MyType("Hello") I get the error Type 'MyType' is less accessible than the value, member, or type: 'val myExternalValue: SubModule.MyType' it is

Discriminated Union initialization

六眼飞鱼酱① 提交于 2019-12-11 10:34:12
问题 Is there a simpler way to initialize this deck of cards using F#? let create() = [ 0..12 ] type Suit = | Spades of list<int> | Hearts of list<int> | Clubs of list<int> | Diamonds of list<int> let spades = create() |> Spades let hearts = create() |> Hearts let clubs = create() |> Clubs let diamonds = create() |> Diamonds Specifically, I would like to simplify the initialization of these four suits. Is there a simpler way to do this? Could I enumerate the types of on this discriminated union

How to use Docker with Paket?

一笑奈何 提交于 2019-12-11 10:31:26
问题 There are several projects in my solution (some production and some test ...) and there is a docker image per each project. Each .fsproj file in the solution contains the line: <Import Project="..\.paket\Paket.Restore.targets" /> But docker's build context is limited by the project's folder and I'd rather not deal with that problem. Can use Paket without the need for referring to parent folders? 回答1: I'm not an expert, but I guess you have two options here: You can keep Paket.Restore.targets

How to switch from error track back to success track in railway-oriented program in F#?

夙愿已清 提交于 2019-12-11 10:16:09
问题 Using AsyncResult from Scott Wlashin and wondering how I can change from the error track to the success track. Pseudo-code: let orchestratorFunction() : AsyncResult<Customer, CustomerError> = asyncResult { let! output1 = callFunction1 arg1 arg2 |> AsyncResult.MapError CustomerError.Val1 let! output2 = callFunction2 arg1 arg2 |> AsyncResult.MapError CustomerError.Val2 let! output3 = callFunction3 arg1 arg2 |> AsyncResult.MapError (fun e -> ********HERE I WANT TO GET BACK TO THE SUCCESS PATH

F# nested List.iter calls

做~自己de王妃 提交于 2019-12-11 10:06:48
问题 I have an F# function and I want to try varying some of the parameters and testing all such combinations. Is this the right approach? (The parentheses get a bit dense...): let MyFunc a b c x y z = ... q let UploadResult a b c x y z q = ... () let a = 5.0 let b = 0 let c = System.DateTime.Today let xList = [-1.0; 0.0; 1.0] let yList = [2; 4; 6; 8; 10] let zList = [0.1; 0.001] xList |> List.iter (fun x -> (yList |> List.iter (fun y -> (zList |> List.iter (fun z -> MyFunc a b c x y z |>

Generic method on record

断了今生、忘了曾经 提交于 2019-12-11 09:59:47
问题 I wonder if there is a better way of implementing a function that accepts records and modify them. So I have entities of two types, both have corresponding files on the disk: type Picture = { Artist : string; File : string } type Book = { Author : string; File : string } I want generic function that can copy both pictures and books. In the OOP world I would probably create common interface IArtefact { File : string } , implement it in both records and then create Move method that works on it.