f#

error FS0193: internal error: Could not load type 'anyType' from assembly 'FSI-ASSEMBLY, Version=0.0.0.0, Culture=neutral, PublicKeyToken=null'

回眸只為那壹抹淺笑 提交于 2019-12-12 00:24:17
问题 When Using Resizable array with any types i can't loop through that array , f# seems not to understand my preDefined Type . here is a sample code : type someData = { Entry:string ; id:int } let datas = new ResizeArray<someData>() let record1 = {someData.Entry = "hiLo" ;someData.id =1234 } datas.Add(record1) let record2 = {someData.Entry = "Lolo" ;someData.id =1224 } datas.Add(record2) let record3 = {someData.Entry = "Hihi" ;someData.id =1231 } datas.Add(record3) let nameOnly = new ResizeArray

F# dynamic operator giving access both to function and function name

試著忘記壹切 提交于 2019-12-11 23:51:33
问题 Given a number of functions test1 , test2 , ... belonging to a module: module Checks = let test1 x = ... let test2 x = ... ... how can the (?) operator be used to give access to both the function name and the function itself? The result should look like: let name, func = Checks?test1 assert(name = "test1") assert(func(x) = Checks.test1(x)) //whatever x is (test1 is known to be pure) 回答1: Here's some sample code that shows off some of this. I use D as the 'dynamic' access of the Checks module

F#: arithmetic operator and loss of polymorphism (value restriction?)

与世无争的帅哥 提交于 2019-12-11 20:42:23
问题 This code doesn't compile: let f = fun x y -> x <<< y // bit shift let g = fun x y -> x <<< y [<EntryPoint>] let main _ = printfn "%d" <| f 1 10 printfn "%d" <| f 1L 10 // error printfn "%d" <| g 1L 10 0 (7,21): error FS0001: This expression was expected to have type int but here has type int64 http://ideone.com/qktsOb I guess the unifier fixed the type parameters associated with f and g upon seeing their first occurrences. What governs this process? I think this is very similar to "value

Loading assembly dynamically from a Typeprovider

倖福魔咒の 提交于 2019-12-11 20:29:21
问题 I'm trying to add a feature to a type provider I'm working on to allow the user to specify a type. with Since type providers cannot provide generic methods, it seems the only way to do it is to reference the assembly that has the type. I've tried to make a proof of concept for this using a type from the Owin library, but I'm running into an issue when trying to use the provided type: It says it cannot find the file, even though it obviously exists, or else the CSharpCodeProvider that I'm

Some basic seq and list questions [duplicate]

半世苍凉 提交于 2019-12-11 18:49:03
问题 This question already has answers here : Closed 7 years ago . Possible Duplicate: Linked list partition function and reversed results Actually I don't care about the input type or the output type, any of seq, array, list will do. (It doesn't have to be generic) Currently my code takes list as input and (list * list) as output let takeWhile predicator list = let rec takeWhileRec newList remain = match remain with | [] -> (newList |> List.rev, remain) | x::xs -> if predicator x then

F# Mailbox vs MailboxProcessor

╄→гoц情女王★ 提交于 2019-12-11 18:38:47
问题 I notice the Mailbox type is encapsulated and can only be used through the use of the MailboxProcessor. It implies that to have an agent to which I can post messages, I'm forced to have a single Mailbox of a single type (or use the existing MailboxProcessor in an exotic way). Should I understand that having multiple Mailbox for a single workflow would inherently result in a bad design? The Ccr clearly gives you that level of freedom. Edit: As Daniel pointed out, if one wants to send multiple

Order of arguments and pipe-right operator

☆樱花仙子☆ 提交于 2019-12-11 18:24:35
问题 Is there a way to simplify the following, so I won't need a runWithTimeout function? let runWithTimeout timeout computation = Async.RunSynchronously(computation, timeout) let processOneItem item = fetchAction item |> runWithTimeout 2000 Edit: Here's why i needed the extra method: let processOneItem item = fetchAction item |> Async.Catch |> runWithTimeout 2000 |> handleExceptions 回答1: Perhaps you mean something like this: let processOneItem item = fetchAction item |> fun x -> Async

F#: Expand a list of tuples of form (string*string list) list using a key

独自空忆成欢 提交于 2019-12-11 18:14:11
问题 The other day I asked how could reduce a list of tuples by grouping one of the elements into arrays (F#: Reduce a list of tuples by grouping one of the elements into arrays). I wish now to learn how to do the opposite of this. Lets say I have this: ("A", ["B"; "C"; "D"; "E"]) and I want to get this: [("A", "B") ; ("A", "C") ; ("A" , "D") ; ("A" , "E")] What is the functional way to do this? How could I do it with a list of elements of this type to be appended? I have tried: let prb = ("A", [

The result of this expression is implicitly ignored. Consider using 'ignore' e.g. 'expr |> ignore', or ' e.g. 'let result = expr'

三世轮回 提交于 2019-12-11 17:25:12
问题 I'm trying to build F# equivalent code for the Python code appearing here, I've the below code: let tripleExponentialSmoothing series slen alpha beta gamma nPreds = let result : float list = [] let mutable smooth = 0. let mutable trend = 0. let seasonals = initialSeasonalComponents series 12 for i in 0..(series.Length+nPreds-1) do match i with | 0 -> // initial values smooth <- series |> Array.head |> float trend <- initialTrend series slen result |> List.append [series |> Array.head |> float

F#: integers to pair of integers

一笑奈何 提交于 2019-12-11 17:18:14
问题 I have function that takes a list of integers as an argument and returns a list of pairs as a result. For example the [1;2;3;4] should be returned as [(1, 2); (3, 4)] I have implemented the below function for this. let listToPairList (list: int list) = let index,pairList = List.foldBack(fun elem (iAcc,listAcc) -> if (iAcc % 2 = 0) then (iAcc - 1,(elem,list.[iAcc + 1])::listAcc) else (iAcc - 1,listAcc)) list (list.Length - 1, []) pairList Now ,I want to do it with using foldBack function but