f#

How to add metadata nodes using the LLVM C Api/llvm-fs bindings

戏子无情 提交于 2019-12-11 05:06:52
问题 I'm trying to add metadata nodes to a program, either onto the instructions or as global metadata. How do I do this with the LLVM C API? It now provides a function LLVMAddNamedMetadataOperand (as found from this question) but I can't seem to see how to use it. This is bound to addNamedMetadataOperand in the llvm-fs bindings. I tried this: addNamedMetadataOperand myModule "foobar" (mDString "cat" 3u) expecting it to make some metadata node called foobar but it doesn't work - complains about

What's the easiest way to do something like delegate multicast in F#

被刻印的时光 ゝ 提交于 2019-12-11 05:05:28
问题 Currently I use this and it works fine: let mutable notify = fun x -> x let wrap f i = f(i); i let a x = printf "%A" x notify <- notify >> (wrap a) notify "ss" Are there any other better approach? and why this doesn't work? let mutable notify = fun x -> x let wrap f i = f(i); i let a x = printf "%A" x let d x = (notify >> (wrap a)) x notify <- d notify "ss" I am not sure why the first example doesn't trigger endless loop, but the second does. It seems mutable function variable (point free

f# remove from own user defined list

╄→尐↘猪︶ㄣ 提交于 2019-12-11 05:05:20
问题 I want to create a function that removes any occurrence of a integer n and returns the list. I know how I want to do it but do not know the command to delete it. Here is the data type type alist = A | L of int * Alist Here's how the data type looks: let l = L(2, L(1, L(2, L(7, L(3, L(2, A)))))) remove 2 l;; should return l = L(1, L(7, L(3, A))) Here is what I have so far: let rec remove n l = match (n, l) with | (n, A) -> l | (n, L(head,tail)) when (n = head) -> I don't know how the how to

F# CsvTypeProvider extracting the same columns from slightly different csv-files

天涯浪子 提交于 2019-12-11 05:05:05
问题 I am creating a program that reads football matches from different CSV files. The columns I am interested in are present in all the files, but the files have a varying number of columns. This left me creating a separate mapping function for each variation of file, with a different sample for each type: type GamesFile14 = CsvProvider<"./data/sample_14.csv"> type GamesFile15 = CsvProvider<"./data/sample_15.csv"> type GamesFile1617 = CsvProvider<"./data/sample_1617.csv"> let mapRows14 (rows:seq

Can a function of type (unit -> unit) have statically resolved type parameters in F#?

醉酒当歌 提交于 2019-12-11 04:55:32
问题 Why isn't this allowed? type Foo() = static member Bar() = () let inline bar<^a>() = //ERROR: unexpected infix operator in pattern (^a : (static member Bar : unit -> unit)()) //Hypothetical usage: let _ = bar<Foo>() ...but this works fine? type Foo() = static member Bar() = new Foo() let inline bar() : ^a = (^a : (static member Bar : unit -> ^a)()) let x : Foo = bar() Are functions with statically resolved type parameters required to return an instance of the resolved type? 回答1: As you

F# piping to/from .net objects

橙三吉。 提交于 2019-12-11 04:46:57
问题 I've noticed difficulty in piping to/from some .NET methods. Toy example let foo = System.String [| 'a'; 'b'; 'c' |] // works let foo = [| 'a'; 'b'; 'c' |] |> System.String // fails // error FS0802: Invalid use of a type name and/or object constructor. let foo = System.String <| [| 'a'; 'b'; 'c' |] // fails the same way let foo = [| 'a'; 'b'; 'c' |] |> new System.String // Fails // error FS0010: Incomplete structured construct at or before this point in expression I'm basically trying to

How do I write a Logary target for my .NET application?

為{幸葍}努か 提交于 2019-12-11 04:28:44
问题 I am trying to get started with Logary. I need to write a new target and I have tried following the following tutorial https://logary.tech/tutorials. I have downloaded Logary.sln from https://github.com/logary/logary, but I am not able to build Logary.sln. When I build it I get 40 errors and all of them say: The command ""paket.exe" restore" exited with code 9009. When I try to add the nuget Logary (latest 5.0) with NuGet manager I get NU1108: Cycle detected. Logary -> Logary (>= 5.0.0). When

C# to F# class transition

三世轮回 提交于 2019-12-11 04:28:02
问题 I'm a C# dev since long ago. I learn F# and use it for scientific purposes/research/approbation works. I find many its functional features powerful but I'm straggling to write classes — the essential thing I know to do very well in C#. What would help me (and the community) is to translate the following C# code. class CoolAttribute : Attribute { } class BaseClass { public BaseClass(int zzz) { // zzz doesn't matter; what matters is that zzz is required } public virtual void XHello() { Console

Can I rewrite this code to avoid the F# error

谁说胖子不能爱 提交于 2019-12-11 04:18:55
问题 I have the following code in F# live version at https://repl.it/repls/CarefulGiganticExtraction let inline tryParse text = let mutable r = Unchecked.defaultof<_> (^a : (static member TryParse: string * ^a byref -> bool) (text, &r)), r let inline tryParseWithDefault (defaultVal:'a) text = match tryParse text with | true, v -> v | _ -> defaultVal type TextBox(text:string) = member this.Text = text type View() = member this.Name = "View" type State = { count: int } module Binder = let inline

How can I return a parameter as a union case value?

删除回忆录丶 提交于 2019-12-11 04:16:25
问题 How can I return a parameter as a union case value? I have the following function: let jumpBlack ((blackChecker:BlackChecker),(blackCheckers:BlackChecker list)) (redPiece:RedPiece) = let yIncrementValue = -1 let minY = 0 match redPiece with | RedPiece.RedChecker rc -> let position = rc.Position |> jump blackChecker.Position yIncrementValue match position with | pos when pos = rc.Position -> RedPiece.RedChecker { rc with Position= position }, blackCheckers | pos when pos.Y = minY -> RedPiece