f#

F# parameter passing

陌路散爱 提交于 2019-12-07 02:39:55
问题 I've always thought that F# had two different ways to pass arguments, curry style and tuple style. Is this actually correct? Isn't it simply one style , curry style, and arguments can either be simple values or tuples. e.g. someFunc (a,b) = isn't this a function with one curry style argument which happens to be a tuple ? Thus allowing me to pass tuples to this function using the pipleline operator? (where the elements of the tuple is named) (1,2) |> someFunc Is this correct? 回答1: This will

F#: is mutual recursion between types and functions possible?

白昼怎懂夜的黑 提交于 2019-12-07 02:39:43
问题 I can use the and keyword to set up mutually recursive function definitions. I can also use and for mutually recursive types, but what if there is a mutually recursive relationship between a type and a function? Is my only option to make the function a member of the type or can I use something similar to and here too? Edit: Adding a simplified pseudo-example that I hope illustrates what I'm trying to do // A machine instruction type type Instruction = Add | CallMethod int (* method ID *) | ..

What are F# quotations?

只谈情不闲聊 提交于 2019-12-07 02:32:07
问题 What are "quotations" in F#, and what are they used for? 回答1: In short, a quotation is metadata that represents the code of a particular function or code snippet. http://fortysix-and-two.blogspot.com/2009/06/traversing-and-transforming-f.html 回答2: See http://msdn.microsoft.com/en-us/library/dd233212.aspx and possibly http://en.wikipedia.org/wiki/Homoiconicity If you want scenarios, I bet you can find some by looking at https://stackoverflow.com/questions/tagged/F%23+quotations 回答3: They are

Abusing pattern matching

六月ゝ 毕业季﹏ 提交于 2019-12-07 02:28:53
问题 I come from C# and find myself in love with the F# pattern matching syntax as it's simpler than C# switch and way more useful. I like to use it as much as possible, is there a performance or any other downside to using it in weird ways like in this example? match 0 with |_ when a<b -> a |_ -> b 回答1: In this particular example, there will be no performance penalty. It is very likely that performance penalty will also be absent in other cases, but to be absolutely sure you'll have to look at

Can I call a function by name in f#?

自闭症网瘾萝莉.ら 提交于 2019-12-07 02:28:31
问题 Is there any way to call a function by name in F#? Given a string, I want to pluck a function value from the global namespace (or, in general, a given module), and call it. I know the type of the function already. Why would I want to do this? I'm trying to work around fsi not having an --eval option. I have a script file that defines many int->() functions, and I want to execute one of them. Like so: fsianycpu --use:script_with_many_funcs.fsx --eval "analyzeDataSet 1" My thought was to write

Is Returning A Random Value From Function A Side Effect?

戏子无情 提交于 2019-12-07 02:13:22
问题 I was working on some F# code and I was working on a function to return a random string from a set of strings. Let's say I had something like this: open System let a = [|"a";"b";"c";"d"|] let rstring (arr:string[]) = let r = new Random() arr.[r.Next(0,3)] let resultstring = rstring a;; My question is this: My understanding of the notion of functional programming is that if a given function has the same input each time it should always return the same output. So in this particular case is

Code analysis in F#

浪子不回头ぞ 提交于 2019-12-07 02:03:09
问题 As a C# developer I've benefited from Microsoft's Code Analysis. In F# however, Code Analysis doesn't seem to be an integrated part of the development cycle. It took me a while to enable CA on an F# project, but this blog helped. Now that I have CA enabled, it seems to produce "wrong" warnings. For instance, I have a declared a record type as type Account = {Number : string} for which I expect structural equality by default. This blog demonstrates that two instances of type Acccount, for

IntelliSense in .fsx and dynamically loaded assemblies

社会主义新天地 提交于 2019-12-07 01:58:47
问题 When dynamically referencing assemblies in .fsx using #I and #r , VS highlights the following usages of imported types and writes "The namespace or module 'XXX' is not defined". Is it ok? For example, in the following code #I @".\Tools\FAKE" #r "FakeLib.dll" open Fake Target "Hello" (fun _ -> trace "hello!") Run "Hello" VS highlights Fake and says "The namespace or module 'Fake' is not defined", it also highlights Target and Run . I have this problem in VS 2010 SP1 and in VS 11 CTP. This

Extending F# List Module

送分小仙女□ 提交于 2019-12-07 01:41:11
问题 I've been adding a few handy methods to some of the F# modules such as List. type Microsoft.FSharp.Collections.FSharpList<'a> with //' static member iterWhile (f:'a -> bool) (ls:'a list) = let rec iterLoop f ls = match ls with | head :: tail -> if f head then iterLoop f tail | _ -> () iterLoop f ls and i'm wondering if it's possible to add mutation? I know List is immutable so how about adding a mutable method to Ref of type List. Something like this. type Ref<'a when 'a :> Microsoft.FSharp

is F# to IronPython/IronRuby as C# is to VB.NET?

老子叫甜甜 提交于 2019-12-07 01:30:50
问题 I just listened to podcast of Chris Smith talking about F# in which he talks about how F# is a language which allows you to approach problems in a different way than in C#/VB.NET, i.e. instead of "pushing bits around" you "chain together data transformations", and that how F# will "become like XML", something that you use in addition to your language of choice (C# or VB.NET) in order to solve certain problems in a more efficient way. This got me to thinking about the relationship of the .NET