f#

Using Selenium Code with F# Canopy

Deadly 提交于 2019-12-11 03:04:37
问题 I am attempting to use Selenium code with F#, I am also using the canopy wrapper. Canopy uses Selenium to make some of it's calls. My issue is I am struggling to covert Selenium code from Java, C# into an F# format, there doesn't seem to be much help on the internet. Is anyone able to shed some light on basic conversions. For example in JavaScript the code to get the title of the webpage is driver.getTitle().then(function(title) { console.log('Page title is: ' + title); }); F# doesn't seem to

Write a sequence of tuples to a csv file f#

本秂侑毒 提交于 2019-12-11 02:57:27
问题 Iam trying to write a sequence of tuples to a csv, but the normal File.WriteAllLines is overloaded by a sequence of tuples. I have tried therefore to flatten my tuples into a sequence of strings. Here is my code:- open System;; open Microsoft.FSharp.Reflection;; let tupleToString (t: string * float) = if FSharpType.IsTuple(t.GetType()) then String.Format("{0},{1}", fst t, snd t) else "";; let testTuple = ("monkey", 15.168);; tupleToString(testTuple);; let testSeqTuple = [("monkey", 15.168); (

Converting float[,] to list in f#?

人走茶凉 提交于 2019-12-11 02:55:00
问题 I have a function that works fine for lists however the input to the function comes as float[,] from external system / language. I read this but when I apply this I get an error float[,] is not compatible with Seq<a'> . However this list is also only of floats. List function: let aggrArraysL data = data |> Seq.groupBy (fun (a, b, c) -> a) |> Seq.map (fun (key, group) -> group |> Seq.reduce (fun (a, b, c) (x, y, z) -> a, b + y, (b * c + y * z * 1.)/(b + y))) Array attempt: let aggrArrays

F# operator overloading strange behavoir

别来无恙 提交于 2019-12-11 02:47:50
问题 Let's say that for some strange reason I want to have this function: let (~-) (str:string) = 42 So I can do something like this and get 42 as result: -"test" val it : int = 42 Which is fine. But now when I do: let a = 100 -a I get: error FS0001: This expression was expected to have type string but here has type int Any idea why is this happening? 回答1: When you define operators using let , the new definition hides all previous definition of the operator. So in your example, you are hiding the

Using unit as Type Parameter and overriding methods

試著忘記壹切 提交于 2019-12-11 02:45:31
问题 I'm basically asking why the following lines of codes do not compile: type IGenericType<'a> = abstract member MyFunc : 'a -> 'a -> 'a type Implementer() = member x.Test () () = () // unit->unit->unit interface IGenericType<unit> with member x.MyFunc a b = b // FS0017 // member x.MyFunc () () = () // FS0017 Just curious if there is a method to make this work as intended. I assume this is a limitation which has to to with the implementation of unit and generics. Im using the following

Differentiating logical from other infix operators

家住魔仙堡 提交于 2019-12-11 02:44:14
问题 I'm trying to parse SQL search conditions and having trouble getting the parser to differentiate logical ( AND , OR ) from other infix operators. I'm parsing them as different nodes (perhaps that's difficult to do), but simplifies the evaluation phase. Here's the relevant code snippet (I can include more if necessary). let opp = OperatorPrecedenceParser<_,_,_>() let scalarExpr = opp.ExpressionParser opp.TermParser <- constant <|> id <|> between lparen rparen scalarExpr <|> scalarExpr //infix

Possible F# type inference limitation

依然范特西╮ 提交于 2019-12-11 02:43:20
问题 I'm quite sure that I run into some kind of limitation, but I do not understand it: type IRunner = abstract member Run : (string -> 'a) -> 'a type T() = let run4 doFun = doFun "4" let run5 doFun = doFun "5" let parseInt s = System.Int32.Parse(s) let parseFloat s = System.Double.Parse(s) let doSomething () = let i = parseInt |> run4 let f = parseFloat |> run4 f |> ignore // Make it more generic -> //let doSomething2 (runner:(string->'a)->'b) = let doSomething2 runner = // Error on the

Pattern combining type test and literal

久未见 提交于 2019-12-11 02:40:15
问题 The active pattern in this question fails to compile after upgrading to VS 2012 RTM. It provides a way to do a type test and match a literal within a single pattern. For example: let (|Value|_|) value = match box value with | :? 'T as x -> Some x | _ -> None let getValue (name: string) (r: IDataReader) = match r.[name] with | null | :? DBNull | Value "" -> Unchecked.defaultof<_> | v -> unbox v Can this be done without the active pattern? I realize a when guard could be used ( :? string as s

Make a List from a Tuple List on F#

◇◆丶佛笑我妖孽 提交于 2019-12-11 02:40:06
问题 Lets say I have a tuple list. Just to make it easier to refer to, its a coordinates with an x and y values. let test = [(1,34);(2,43);(3,21);(1,51);(2,98);(3,56);(1,51)] I want to make another list using test so that if I only want value which has an x value of 1, it would return [34;51;51] 回答1: You need to filter the list first to get tuples that have an x value of 1, then map the results to get the y value : [(1,34);(2,43);(3,21);(1,51);(2,98);(3,56);(1,51)] |> List.filter (fun (x,_)->x=1)

Indentation, expressions, statements and StackOverflowException with FParsec - Errors

与世无争的帅哥 提交于 2019-12-11 02:36:16
问题 I test indentation with FParsec, according to this implementation, but when I make it a little more complex by adding expressions (literals, lists, tuples and arithmetic operations), allowing expressions to top-level, and adding a variable creation statement; I first get a StackOverflowException error . In my opinion, this is because the expression parser is solicited in such a way as to make an infinite loop in the program. I see no other reason, however, I don't know how to fix this problem