f#

Summing over lists of arbitrary levels of nestedness in F#

£可爱£侵袭症+ 提交于 2021-02-08 12:37:13
问题 I'm trying to create an F# function that will return the sum of a list of int s of arbitrary nestedness. Ie. it will work for a list<int> , a list<list<int>> and a list<list<list<list<list<list<int>>>>>> . In Haskell I would write something like: class HasSum a where getSum :: a -> Integer instance HasSum Integer where getSum = id instance HasSum a => HasSum [a] where getSum = sum . map getSum which would let me do: list :: a -> [a] list = replicate 6 nestedList :: [[[[[[[[[[Integer]]]]]]]]]]

F# error 'error FS0039: The namespace or module 'MySql' is not defined'?

微笑、不失礼 提交于 2021-02-08 08:59:19
问题 Hello I try to connect F# and MySQL database, but i got fallowing error :error FS0039: The namespace or module 'MySql' is not defined. So far,i tried to reference the folder which contains MySQL.Data.dll:project -> add reference->browse -> C:\Program Files (x86)\MySQL\MySQL Connector Net 6.3.6\Assemblies\v2.0 Also i tired to reference MySQL.Data,too. But each time,i get this error. Thanks for your help. Regards, 回答1: The F# interactive window is unaware of your project references, so you need

System.Linq.Enumerable.OfType<T> - is there a F# way?

送分小仙女□ 提交于 2021-02-08 05:39:15
问题 I'm looking to use the F# WSDL Type Provider. To call the web service I am using, I need to attach my client credentials to the System.ServiceModel.Description.ClientCredentials . This is the C# code I have: var serviceClient = new InvestmentServiceV1Client.InvestmentServiceV1Client(); foreach (ClientCredentials behaviour in serviceClient.Endpoint.Behaviors.OfType<ClientCredentials>()) { (behaviour).UserName.UserName = USERNAME; (behaviour).UserName.Password = PASSWORD; break; } This is the F

F# Removing duplicates from list with function

我的梦境 提交于 2021-02-08 05:05:31
问题 I want to create a function that takes a list and returns a list with removed duplicates. let removedupes list1 = let list2 = [] let rec removeduprec list1 list2 = match list1 with | [] -> list2 | head :: tail when mem list2 head = false -> head :: removeduprec tail list2 | _ -> removeduprec list1.Tail list2 removeduprec list1 list2 Im using this "mem" function to go trough the list and see if the value already exists and in that case i want to continue with the recursion. let rec mem list x

FParsec failing on optional parser

蹲街弑〆低调 提交于 2021-02-07 21:12:32
问题 I am currently learning the FParsec library, but I have come across an issue. When I want to parse an optional string and continue parsing as normal afterwards, FParsec will return a fatal error on the optional parser, rather than returning None as I expect. The below working code sample illustrates my point: open System open FParsec type AccountEntity = | Default | Entity of string let pEntity = let isEntityFirstChar c = isLetter c let isEntityChar c = isLetter c || isDigit c (many1Satisfy2L

FParsec failing on optional parser

只愿长相守 提交于 2021-02-07 21:11:51
问题 I am currently learning the FParsec library, but I have come across an issue. When I want to parse an optional string and continue parsing as normal afterwards, FParsec will return a fatal error on the optional parser, rather than returning None as I expect. The below working code sample illustrates my point: open System open FParsec type AccountEntity = | Default | Entity of string let pEntity = let isEntityFirstChar c = isLetter c let isEntityChar c = isLetter c || isDigit c (many1Satisfy2L

FParsec failing on optional parser

穿精又带淫゛_ 提交于 2021-02-07 21:10:34
问题 I am currently learning the FParsec library, but I have come across an issue. When I want to parse an optional string and continue parsing as normal afterwards, FParsec will return a fatal error on the optional parser, rather than returning None as I expect. The below working code sample illustrates my point: open System open FParsec type AccountEntity = | Default | Entity of string let pEntity = let isEntityFirstChar c = isLetter c let isEntityChar c = isLetter c || isDigit c (many1Satisfy2L

F# working with DataReader

£可爱£侵袭症+ 提交于 2021-02-07 19:16:08
问题 let reader = selectCommand.ExecuteReader() let getBytesData (x : IDataReader) = let len = reader.GetBytes(1, int64 0, null, 0, 0); // Create a buffer to hold the bytes, and then // read the bytes from the DataTableReader. let buffer : byte array = Array.zeroCreate (int32 len) x.GetBytes(1, int64 0, buffer, 0, int32 len) |> ignore buffer let retVal = List [ while reader.Read() do yield (reader.GetString(0), getBytesData reader, reader.GetDateTime(2)) ] I have above code to read bytes[] from

F# working with DataReader

烂漫一生 提交于 2021-02-07 19:15:03
问题 let reader = selectCommand.ExecuteReader() let getBytesData (x : IDataReader) = let len = reader.GetBytes(1, int64 0, null, 0, 0); // Create a buffer to hold the bytes, and then // read the bytes from the DataTableReader. let buffer : byte array = Array.zeroCreate (int32 len) x.GetBytes(1, int64 0, buffer, 0, int32 len) |> ignore buffer let retVal = List [ while reader.Read() do yield (reader.GetString(0), getBytesData reader, reader.GetDateTime(2)) ] I have above code to read bytes[] from

Defining a Message Passing domain with very many message types

会有一股神秘感。 提交于 2021-02-07 18:10:21
问题 Most F# Message Passing examples I've seen so far are working with 2-4 message types, and are able to utilize pattern matching to direct each message to its proper handler function. For my application, I need hundreds of unique message types due to the different nature of their handling and required parameters. So far, each message type is its own record type with a marker interface attached, because including hundreds of types in a single discriminated union would not be very pretty - and