f#

How to connect to SQL Server Compact Edition 4.0 with a type provider in F#?

[亡魂溺海] 提交于 2019-12-06 01:45:49
问题 I'm attempting to connect to a SQL Server Compact Edition database from F#, and attempting to use a type provider. This is in the Visual Studio 11 Beta, so I realize there might be an issue because of that, but I think it's more likely that I just don't have the know-how yet. However, I have noticed that there's no CE-specific type provider in Microsoft.FSharp.Data.TypeProviders and I'm unsure that a regular SqlDataConnection will do the trick, so that may be the issue right there. However,

Strategy pattern in F#

岁酱吖の 提交于 2019-12-06 01:40:04
问题 In C# I have the following code: public class SomeKindaWorker { public double Work(Strategy strat) { int i = 4; // some code ... var s = strat.Step1(i); // some more code ... var d = strat.Step2(s); // yet more code ... return d; } } This is a piece of code that can do some kind of work by using a provided strategy object to fill in parts of the implementation. Note: in general the strategy objects do not contain state; they merely polymorphically provide implementations of individual steps.

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

How to wrap sprintf conditionally in F#?

允我心安 提交于 2019-12-06 01:37:37
问题 I have read a similar question: Magic sprintf function - how to wrap it?, but my requirement is a little bit different, so I am wondering whether it's doable or not. First, I want to explain the scenario a little bit, I currently have a trace function like let Trace traceLevel ( fs : unit -> string) = if traceLevel <= Config.TraceLevel then Trace.WriteLine <| fs() So the function "fs" is called to generate a string only if traceLevel is less than or equal to the trace level specified by the

What would be an idiomatic F# way to scale a list of (n-tuples or list) with another list, also arrays?

一世执手 提交于 2019-12-06 01:22:48
Given: let weights = [0.5;0.4;0.3] let X = [[2;3;4];[7;3;2];[5;3;6]] what I want is: wX = [(0.5)*[2;3;4];(0.4)*[7;3;2];(0.3)*[5;3;6]] would like to know an elegant way to do this with lists as well as with arrays. Additional optimization information is welcome You write about a list of lists, but your code shows a list of tuples. Taking the liberty to adjust for that, a solution would be let weights = [0.5;0.4;0.3] let X = [[2;3;4];[7;3;2];[5;3;6]] X |> List.map2 (fun w x -> x |> List.map (fun xi -> (float xi) * w ) ) weights Depending on how comfortable you are with the syntax, you may prefer

F# method returns null instead of Option

别来无恙 提交于 2019-12-06 01:19:31
问题 I develop F# application .net 4.6.1 on VS2015 . i have methods: type CommonHelper = static member SideEffectOnNull act x = if x = null then act(); x else x static member SideEffectOnNotNull act x = if x <> null then act(); x else x ... static member GetPerformanceCounter ( fname: CounterFullName ) = let getCounterInternal ( counterFullName: CounterFullName ) = Log.Information("Getting counter: {category}\\{name}\\{instance} ", counterFullName.Category, counterFullName.Name, counterFullName

F# - What is array<'T>?

故事扮演 提交于 2019-12-06 01:18:23
问题 In this previous question I learnt that in F# an array<'T> is not the same as System.Array . VS tells me that array<'T> inherits System.Array and has the full name Microsoft.FSharp.Core.array<_> and some additional Interfaces. However MSDN says that array<'T> is a type abbreviation of System.Array . And that it has the notation arr.[i] to get and set items. So for my lesson, is array<'T> a type abbreviation that includes type extensions and additional Interfaces? Where is the best place to

How to install and use F# Powerpack in Mono?

耗尽温柔 提交于 2019-12-06 01:07:35
问题 I need to install use F# powerpack. I use mono version 2.10.2 on Mac. mono --version Mono JIT compiler version 2.10.2 (tarball Mon Apr 18 09:14:01 MDT 2011) Copyright (C) 2002-2011 Novell, Inc and Contributors. www.mono-project.com TLS: normal SIGSEGV: normal Notification: kqueue Architecture: x86 Disabled: none Misc: debugger softdebug LLVM: yes(2.9svn-mono) GC: Included Boehm (with typed GC) Installation. Download the powerpack zip file from here. Unzip the file to directory ~/bin . Add the

Explicit type recursion in F#

我的梦境 提交于 2019-12-06 01:00:16
问题 Inspired by this question: Is explicit type recursion possible in F#? type 'a Mu = In of 'a Mu 'a let unIn (In x) = x This code unfortunatly gives "Type parameter cannot be used as type constructor. Remarks: This construct is used in the paper Functional Programming with Overloading and Higher-Order Polymorphism, for example. Example of usage (taken from here): type ('a, 'b) ListX = | Nil | Cons of 'a * 'b type 'a List = ListX Mu 回答1: No, this is not possible. Specifically, generics in F#

F# transform list to a tree

折月煮酒 提交于 2019-12-06 00:50:19
问题 I have a list of tuples int*string where int is level and string is name let src = [ (0, "root"); (1, "a"); (2, "a1"); (2, "a2"); (1, "b"); (2, "b1"); (3, "b11"); (2, "b2"); ] and i need to transform it to following let expectingTree = Branch("root", [ Branch("a", [ Leaf("a1"); Leaf("a2") ]); Branch("b", [ Branch("b1", [Leaf("b11")]); Leaf("b2") ]); ]); Below is the way how i did it, but could anybody advice with a better way to achieve that. I'm new to F#, and C# code to do the same thing