f#

Reverse currying?

╄→гoц情女王★ 提交于 2019-12-10 03:39:45
问题 I'd like to compose functions in a certain way. Please consider these 2 functions in pseudocode (not F#) F1 = x + y F2 = F1 * 10 // note I did not specify arguments for F1, 'reverse curry' for lack of a better word What I would like for F# to do is figure out that since let F1 x y = x + y //val F1 : int -> int -> int the code let F2 = F1 * 10 would give me the same signature as F1: val F2 : int -> int -> int , and calling F2 2 3 would result in 50: (2 + 3) * 10. That would be rather clever...

F# Type Providers and Continuous Integration, Part 2

╄→尐↘猪︶ㄣ 提交于 2019-12-10 03:28:59
问题 This is a (actually it is several) follow-up question to my previous question on F# Type Providers and Continuous Integration. It seems to me that it would be a good idea to use the SqlDataConnection type provider as a compile-time check that the code/database integrity remains intact in feature-branch driven development; you would know at every commit/build that no changes have been made to the code that has not also been applied to the database, assuming that building the database is also a

Type inference in sequence expressions in F#

二次信任 提交于 2019-12-10 03:01:02
问题 I think I do not quite understand how F# infers types in sequence expressions and why types are not correctly recognized even if I specify the type of the elements directly from "seq". In the following F# code we have a base class A and two derived classes, B and C: type A(x) = member a.X = x type B(x) = inherit A(x) type C(x) = inherit A(x) If I try to "yield" their instances in a simple sequence expressions, I get two errors: // Doesn't work, but it makes sense. let testSeq = seq { yield A

Repeatable pattern matching

混江龙づ霸主 提交于 2019-12-10 02:58:53
问题 Consider the following simple example. type PaymentInstrument = | Check of string | CreditCard of string * DateTime let printInstrumentName instrument = match instrument with | Check number-> printfn "check" | CreditCard (number, expirationDate) -> printfn "card" let printRequisites instrument = match instrument with | Check number -> printfn "check %s" number | CreditCard (number, expirationDate) -> printfn "card %s %A" number expirationDate As you can see the same pattern matching logic is

F# Type Providers and Data Processing

杀马特。学长 韩版系。学妹 提交于 2019-12-10 02:56:31
问题 In a previous question (Working with heterogenous data in a statically typed language), I asked about how F# handles standard tasks in data analysis, such as manipulating an untyped CSV file. Dynamic langauges excel at basic tasks like data = load('income.csv') data.log_income = log(income) In F#, the most elegant approach seems to be the question mark (?) operator. Unfortunately in the process we lose static typing and still need type annotations here and there. One of the most exciting

Signing an F# Assembly (Strong name component)

南楼画角 提交于 2019-12-10 02:43:34
问题 I found this article on CodeProject: http://www.codeproject.com/Articles/512956/NET-Shell-Extensions-Shell-Context-Menus and thought it would be nice to give it a try, but in F#. So I came up with the following code: open System open System.IO open System.Text open System.Runtime.InteropServices open System.Windows.Forms open SharpShell open SharpShell.Attributes open SharpShell.SharpContextMenu [<ComVisible(true)>] [<COMServerAssociation(AssociationType.ClassOfExtension, ".txt")>] type

F# Lazy Evaluation vs Non-Lazy

强颜欢笑 提交于 2019-12-10 02:40:00
问题 I'm just beginning F# so please be kind if this is basic. I've read that a function marked lazy is evaluated only once and then cached. For example: let lazyFunc = lazy (1 + 1) let theValue = Lazy.force lazyFunc Compared to this version which would actually run each time it's called: let eagerFunc = (1 + 1) let theValue = eagerFunc Based on that, should all functions be made lazy? When would you not want to? This is coming from material in the book "Beginning F#" . 回答1: First of all, it may

How does the option type work in F#

心不动则不痛 提交于 2019-12-10 02:23:25
问题 So I've been reading the Expert F# book by Apress, mostly using it as a reference when building a toy-ish F# library, but there's one thing I've failed to grasp and that's the "Option" type. How does it work and what is it's real world usage? 回答1: The option type is at least similar to Nullable<T> and reference types in C#. A value of type Option<T> is either None which means there's no encapsuated value, or Some with a particular value of T . This is just like the way a Nullable<int> in C#

C#-style event accessors for CLI events in F#

戏子无情 提交于 2019-12-10 02:21:06
问题 I am exposing an event from F# to C# like this: let event = new DelegateEvent<EventHandler>() member x.Ping() = event.Trigger([| x; EventArgs.Empty |]) [<CLIEvent>] member x.PingEvent = event.Publish But I'd like some code to run whenever handlers are added or removed. I think this can be done in C# like this: public event EventHandler PingEvent { add { //do something } remove { //do something } } How do I write the above in F#? 回答1: In F#, you can define events with implementations of the

F#: Mutually recursive functions [duplicate]

扶醉桌前 提交于 2019-12-10 02:06:09
问题 This question already has answers here : Closed 9 years ago . Possible Duplicate: [F#] How to have two methods calling each other? Hello all, I Have a scenario where I have two functions that would benefit from being mutually recursive but I'm not really sure how to do this in F# My scenario is not as simple as the following code, but I'd like to get something similar to compile: let rec f x = if x>0 then g (x-1) else x let rec g x = if x>0 then f (x-1) else x 回答1: You can also use let rec ..