f#-3.0

Pattern combining type test and literal

久未见 提交于 2019-12-11 02:40:15
问题 The active pattern in this question fails to compile after upgrading to VS 2012 RTM. It provides a way to do a type test and match a literal within a single pattern. For example: let (|Value|_|) value = match box value with | :? 'T as x -> Some x | _ -> None let getValue (name: string) (r: IDataReader) = match r.[name] with | null | :? DBNull | Value "" -> Unchecked.defaultof<_> | v -> unbox v Can this be done without the active pattern? I realize a when guard could be used ( :? string as s

Getting compile error on provided type

我怕爱的太早我们不能终老 提交于 2019-12-10 13:48:39
问题 I'm working on a TypeProvider that reads an XSD file and provides a type for each type defined in the XSD. However I have a problem in the below code type schema = XmlProviders.Schema<"file.xsd"> type Bazzer = { Sum : XmlProviders.bar } on the last line I get a compilation error saying that XmlProviders.bar does not exist. The implementation of how I define the types are as follows let defineType (xType : XElement) = let name = xType.Attribute(XName.Get "name").Value let t =

What is the purpose of flexible type annotation in F#?

走远了吗. 提交于 2019-12-10 12:57:15
问题 I'm studying F# and I don't understand the purpose of flexible types, or better, I can't understand the difference between writing this: set TextOfControl (c : Control) s = c.Text <- s and writing this: set TextOfControl (c : 'T when 'T :> Control) s = c.Text <- s where Control is the System.Windows.Forms.Control class. 回答1: There is no difference in your example. If return types are constrained, you start seeing the difference: let setText (c: Control) s = c.Text <- s; c let setTextGeneric

F#: Some, None, or Exception?

半世苍凉 提交于 2019-12-08 14:59:45
问题 I have been teaching myself F# lately, and I come from an imperative (C++/C#) background. As an exercise I have been working on functions that can do stuff with matrices, like add, multiply, get determinants, etc. Everything is going well in this regard, but I find that maybe I am not making the best decisions when it concerns handling invalid inputs, for example: // I want to multiply two matrices let mult m1 m2 = let sizeOK = validateDims m1 m2 // Here is where I am running to conceptual

Type provider for MySql

淺唱寂寞╮ 提交于 2019-12-07 17:23:15
问题 I've been searching for an example on how to connect to a MySql database and use F# type providers but I could not find anything online. Can anyone give me a clue? What - if any - extra packages do I need? Do I use SqlDataConnection or SqlEntityConnection . Excuse my ignorance but I'm totally lost. Any and all help is appreciated. I love the idea of type providers and have a fair amount of experience with functional programing but it's the setup around this that gets me. 回答1: I don't think

F# Type Providers and REST apis

时光总嘲笑我的痴心妄想 提交于 2019-12-07 04:59:05
问题 Is there any reason why the default plug and play F# type providers to web services is soap based wsdl? Is it because of a lack of formal contracts in REST? Such that each REST api may differ significantly and hence making a general REST provider difficult to provide? 回答1: Type providers need machine-readable type schema to do their jobs well. 回答2: Type providers need schema. So you could use Open Data Protocol that is REST + schema. For that task you could use ODataTypeProvider that is

Understanding a change to protected/base member usage in F# 3.0

99封情书 提交于 2019-12-07 03:22:38
问题 F# 3.0 adds stricter checks for calls to base and protected members. I have something like the following abstract class in C# that has protected static helper methods to be used by derived classes. public abstract class Processor { public abstract void Process(); protected static void Helper(object arg) { } } In F#, one of those helper methods is passed as a first-class function: type DerivedProcessor() = inherit Processor() let init f = f () override x.Process() = init Processor.Helper It

Providing connection string to Linq-To-Sql data provider

让人想犯罪 __ 提交于 2019-12-06 23:47:26
问题 Is there a way to provide a connection string to Linq-To-Sql data provider in F# from App.Config file. I have tried the following just for testing: let mutable connString = @"Data Source=PCSQLEXPRESS;Initial Catalog=NortwindDB;Integrated Security=True" type SqlConnection = SqlDataConnection<ConnectionString = connString> but I get an error message "This is not a constant expression or valid custom attribute value" Thanks 回答1: The type provider itself requires a hard-coded connection string

How to obtain F# powerpack for F# 3.0

自作多情 提交于 2019-12-06 02:06:29
问题 I'm using VS11 Beta on Win 8 Consumer Preview. After install VS11 Beta I have F# 3.0 SDK installed. But I'm not able to find a compatible FSharp.PowerPack.dll as CodePlex only provides PowerPack for F# 2.0. Any idea how to deal with this? 回答1: You can compile the PowerPack sources on your own (against F# 3.0), to make your own copy of the library. Alternatively, I think a binding redirect in your final foo.exe.config, along the lines of https://stackoverflow.com/a/9648673/19299 but

Type provider for MySql

杀马特。学长 韩版系。学妹 提交于 2019-12-06 01:39:30
I've been searching for an example on how to connect to a MySql database and use F# type providers but I could not find anything online. Can anyone give me a clue? What - if any - extra packages do I need? Do I use SqlDataConnection or SqlEntityConnection . Excuse my ignorance but I'm totally lost. Any and all help is appreciated. I love the idea of type providers and have a fair amount of experience with functional programing but it's the setup around this that gets me. I don't think there is out-of-the box type provider that would work with MySQL at the moment. However, Ross McKinlay has