f#

F# Equivalent of Destructor

余生长醉 提交于 2019-12-14 03:40:08
问题 I am translating a C# class that wraps an unmanaged library to F#. I have run into the seemingly simple problem of rewriting the destructor that follows. class Wrapper { // P/Invoke ellided private SomeType x; public Wrapper() { x = new SomeType(); Begin(); } public ~Wrapper() { End(); } The simplified F# code I have at this point is as follows: type Wrapper() = [<Literal>] static let wrappedDll = "Library.dll" [<DllImport(wrappedDll , EntryPoint = "Begin")>] static extern void Begin() [

F# : not sure how to start [closed]

China☆狼群 提交于 2019-12-14 03:33:41
问题 Closed. This question is off-topic. It is not currently accepting answers. Want to improve this question? Update the question so it's on-topic for Stack Overflow. Closed 4 years ago . Need help with this, Write a function, that takes 2 StraightLine and returns the intersecting point as a tuple (x,y) . If there is no solution, there shall be used an "Exception" Change your solution in assignment "1", so instead of using an "Exception" you need to use the option "None" if there is no solution.

Why upcast is not necessary in this let bound function?

♀尐吖头ヾ 提交于 2019-12-14 03:12:16
问题 According to MSDN Upcasting is applied automatically when you pass arguments to methods on an object type. However, for let-bound functions in a module, upcasting is not automatic, unless the parameter type is declared as a flexible type. But type C() = member this.T() = () type D() = inherit C() let myfun (x: C)= () let d = D() myfun d I don't need to upcast at all. 回答1: Have a look at the F# spec where it says: This means that F# functions whose inferred type includes an unsealed type in

F# not returning at end of expression

别说谁变了你拦得住时间么 提交于 2019-12-14 02:39:29
问题 I have an issue where an F# program is not returning at the end of an expression and ends up executing the next expression below it. The two expressions as they appear in the file: let startCycle = printfn "startCycle" (0, "") let blah = printfn "blah" (0, "") And when startCycle is called it will print both messages to the console. Stepping through this with the debugger it goes from the first (0, "") to printfn "blah" and returns when it hits the second (0,"") . I've checked the spacing

F# query concatenation

爱⌒轻易说出口 提交于 2019-12-14 01:36:27
问题 I am using SqlDataConnection data provider in F# to migrate some rows, part of that migration is to make a join between 3 tables like this, think of it as an inheritance of tables A , B , C where B and C inherit from A so the thing is I need to get is (in Linq-like): Bs.Join(As, b.PK, a.FK).Select(new {...}) .Concat(Cs.Join(As, c.PK, a.FK).Select(new {...}) In F# , the closest I got to this was: let result = seq { yield! query { ... } yield! query { ... } } but I've been told this will

Type inference: functions vs types

Deadly 提交于 2019-12-14 01:19:29
问题 I am learning F# and I don't understand how type inference and generics work in this language. For example, I can declare a generic min function and use it with parameters of different types: let min a b = if a < b then a else b let smallestInt = min 3 5 let smallestFloat = min 3.0 5.0 But if I try the same thing with a type, it doesn't work: type Point2D(x, y) = member this.X = x member this.Y = y let float32Point = new Point2D(0.0f, 1.0f) let intPoint = new Point2D(0, 1) // This expression

F# ionide websharperserverclient - how to run

北战南征 提交于 2019-12-14 01:00:44
问题 I have a problem with running websharperserverclient template app from ionide project generator, and cannot find any information on the web how to do it - the closest thing i got was this question - I actually tried to run it with xsp4 in the project folder (where the Web.config file is) but every time got a 404 (screenshot attached: xsp4 error). Of course before starting xsp i run the ./build.sh (or FAKE build ) script and it finishes with no errors. I had no problems with websharpersuave

Comparing two lists for unique items in each

ぃ、小莉子 提交于 2019-12-14 00:54:53
问题 I have two collections (they happen to be arrays, but it doesn't really matter, I think): L and R . They are both sorted and now I want to compare them. I want to end up with two collections: one for each input array containing the items which were not in the other. I could just take the first item from L and then search R and, if there isn't a match, add it to my "unique" collection ( Lu ). But that's extremely inefficient, and I am expecting to have some very large collections to process in

Why is the signature of foldBack so much different from fold in F#?

為{幸葍}努か 提交于 2019-12-14 00:47:02
问题 There are at least 2 things I don't understand about it: refactoring from left side to right side folding requires a lot of changes not only in signature but in every place depended on the folder function there is no way to chain it with regard to the list without flipping the parameters List.foldBack : ('T -> 'State -> 'State) -> 'T list -> 'State -> 'State List.fold : ('State -> 'T -> 'State) -> 'State -> 'T list -> 'State Any good reason for why would someone put all parameters in reverse

function to Visualizing Data in a Grid in F#

坚强是说给别人听的谎言 提交于 2019-12-13 20:26:33
问题 I wrote the following function to view data in a grid from F# interactive: open System.Windows.Forms let grid x = let form = new Form(Visible = true) let data = new DataGridView(Dock = DockStyle.Fill) form.Controls.Add(data) data.DataSource <- x |> Seq.toArray How can I make it work for both 1D and 2D seqs? say, grid [1,2,3] or grid[(1,0);(2,0);(3,0)];; works fine but grid [1;2;3];; would not work. another question is, why do I have to add the `|>Seq.toArray to make it work? 回答1: As desco