f#

type mismatch error for async chained operations

天大地大妈咪最大 提交于 2019-12-10 18:57:12
问题 Previously had a very compact and comprehensive answer for my question. I had it working for my custom type but now due to some reason I had to change it to string type which is now causing type mismatch errors. module AsyncResult = let bind (binder : 'a -> Async<Result<'b, 'c>>) (asyncFun : Async<Result<'a, 'c>>) : Async<Result<'b, 'c>> = async { let! result = asyncFun match result with | Error e -> return Error e | Ok x -> return! binder x } let compose (f : 'a -> Async<Result<'b, 'e>>) (g

Improving the readability of a FParsec parser

六月ゝ 毕业季﹏ 提交于 2019-12-10 18:47:20
问题 I have a hand-written CSS parser done in C# which is getting unmanageable and was trying to do it i FParsec to make it more mantainable. Here's a snippet that parses a css selector element made with regexes: var tagRegex = @"(?<Tag>(?:[a-zA-Z][_\-0-9a-zA-Z]*|\*))"; var idRegex = @"(?:#(?<Id>[a-zA-Z][_\-0-9a-zA-Z]*))"; var classesRegex = @"(?<Classes>(?:\.[a-zA-Z][_\-0-9a-zA-Z]*)+)"; var pseudoClassRegex = @"(?::(?<PseudoClass>link|visited|hover|active|before|after|first-line|first-letter))";

F#: Recursive Functions: test whether an element is a member of a given list

别等时光非礼了梦想. 提交于 2019-12-10 18:33:45
问题 I'm trying to figure out how to code this. Implement in F# a function that tests whether an element is a member of a given list. Here is the type I want. val memberof : ’a * ’a list -> bool when ’a : equality Here are examples of the function in action. memberof 1 [1;2;3];; error FS0003: This value is not a function and cannot be applied memberof (1,[1;2;3]);; val it : bool = true memberof (1, []);; val it : bool = false memberof (1,[2;3;4]);; val it : bool = false heres what i've put

Can you list the contents of a namespace or module in F#

左心房为你撑大大i 提交于 2019-12-10 18:33:37
问题 Similar to this question about clojure, is it possible to list the contents of a namespace or module in F#? When I open a namespace for a loaded DLL I'm not receiving an error that the namespace doesn't exist, but then when I try to use the documented functions I'm seeing errors that the namespace doesn't exist. I'm looking for a programatic way of listing values and methods and not relying on the IDE. For example if I loaded up the F# repl I'm looking for something similar to: > #r "mylib

Why doesn't bindingRedirect affect FSharp.Core version

陌路散爱 提交于 2019-12-10 18:26:32
问题 I have a unit test project that targets F# runtime 4.4.1. It has an app.config with the bindingRedirect section: <dependentAssembly> <Paket>True</Paket> <assemblyIdentity name="FSharp.Core" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> <bindingRedirect oldVersion="0.0.0.0-65535.65535.65535.65535" newVersion="4.4.1.0" /> </dependentAssembly> However, when I run tests I get a runtime error: Could not load file or assembly 'FSharp.Core, Version=4.3.0.0, Culture=neutral, PublicKeyToken

How can I have a function that returns different types in F#?

心已入冬 提交于 2019-12-10 18:25:51
问题 I've made a scanner in F#. Currently it returns a list of bunch of tuples with type (Token, string). Ideally I'd like to return a list of tuples that might contain different types. For example: (Token, string) //if it's an identifier (Token, float) //if it's a float. (Token, int) //etc So, Basically I'd like to return type (Token, _) but I'm not sure how to specify this. Right now it just has errors complaining of mismatched types. I'm looking through my book, and wikibooks, but I'm not

Finding an index of a max value of a list in F#

时光总嘲笑我的痴心妄想 提交于 2019-12-10 18:25:28
问题 I'm trying to write a function that takes a list for example let list = [5;23;29;1] let x = max list // This will return 2 because 29 will be the max value and it's "indexed" at position 2 I'm not sure about how to go about writing the max function Since my list will only contain four elements I currently have some code like this let list = (1, newMap1 |> getScore) :: (2, newMap2 |> getScore) :: (3, newMap3 |> getScore) :: (4, newMap4 |> getScore) :: [] I consider this a terrible approach but

F# Recursive Functions: make list items unique

删除回忆录丶 提交于 2019-12-10 18:23:54
问题 let rec isolate (l:'a list) = match l with | [] -> [] | x::xs -> if memberof(x,xs) then remove (x,l) else isolate xs I've already created functions memberof and remove, the only problem is that when line 6 remove(x,l) executes it doesn't continue with isolate(xs) for continued search through the list. Is there a way to say, if x then f(x) and f(y) ? 回答1: As you are using F# immutable lists, the result of remove needs to be stored somewhere: let rec isolate (l:'a list) = match l with | [] -> [

Is there any documentation on how to use Glimpse with F# and Suave? [closed]

杀马特。学长 韩版系。学妹 提交于 2019-12-10 18:23:30
问题 Closed . This question needs details or clarity. It is not currently accepting answers. Want to improve this question? Add details and clarify the problem by editing this post. Closed 3 years ago . I am trying to see if there are any instructions/documentation on how to use Glimpse in an F# project? I looked through the list of adapters they have on their website and I didn't see anything specific to F#. They have ones for ASP.NET MVC and EF but if you using something like Suave (https:/

F# Type Provider development: When providing a method, how to access parameters of variable number and type?

此生再无相见时 提交于 2019-12-10 18:22:26
问题 My question is this: How can I splice the expressions from a list into a quotation when I don't know the number and types of those expressions at design time? At the bottom I've included the full code for a type provider. (I've stripped the concept down to demonstrate the problem.) My issue occurs at these lines: let func = ProvidedMethod((*...*), InvokeCode = fun args -> <@@ let stringParts = args |> List.mapi (fun i arg -> if paramTypes.[i] = typeof<int> then sprintf "%i" (%%arg: int)... On