f#

Can you propose a more elegant way to 'tokenize' c# code for html formatting?

余生长醉 提交于 2019-12-07 16:36:29
问题 (This question about refactoring F# code got me one down vote, but also some interesting and useful answers. And 62 F# questions out of the 32,000+ on SO seems pitiful, so I'm going to take the risk of more disapproval!) I was trying to post a bit of code on a blogger blog yesterday, and turned to this site, which I had found useful in the past. However, the blogger editor ate all the style declarations, so that turned out to be a dead end. So (like any hacker), I thought "how hard can it be?

F# with sqlclr in a reasonably safe way and scripted assembly

柔情痞子 提交于 2019-12-07 16:21:22
问题 There exist some blog posts about how to use F# with SQLCLR in SQL Server that are helpful: http://richardminerich.com/2015/12/a-safer-way-to-use-f-with-sql-clr/, http://thelastexpression.blogspot.com/2012/04/f-agents-and-sqlclr.html, https://rojepp.wordpress.com/2011/08/03/f_on_sqlclr/, Can the F# core libs be SQLCLR-approved? and for the C# approach: http://www.sqlservercentral.com/Authors/Articles/Solomon_Rutzky/294002/ I am wondering/hoping that with the passage of time there is a blog

F# pattern matching of .Net constants

徘徊边缘 提交于 2019-12-07 15:08:41
问题 The code in the next example, open System.Drawing let testColor c = match c with | Color.Black -> 1 | Color.White -> 0 | _ -> failwith "unexpected color" doesn't compile. The error is Error 1 The field, constructor or member 'Black' is not defined . How do I pattern match against .Net constants or enums that start with capital letters? For what it's worth, the compiler is "Microsoft (R) F# 2.0 Interactive build 4.0.30319.1". 回答1: You can't pattern-match against arbitrary object values. Use an

Type provider and static argument in F#

六眼飞鱼酱① 提交于 2019-12-07 14:48:01
问题 I have a library, Library_1, which compiles correctly and defines a provided type : type modelforexcel = FSharpx.ExcelFile<@"template.xls", "Brokernet", true> When I include this library in another project, Library_2, the compiler complains that it can't find any "Brokernet.template.xls", at the root of the new Library_2 project. Error 4 'C:\Library_2\template.xls' could not be found. Check the spelling of the file name, and verify that the file location is correct. I would like the type to

Accord.net Cobyla solver returns success when there are no feasiable solutions

不打扰是莪最后的温柔 提交于 2019-12-07 14:45:55
问题 I'm using Accord.Net's Cobyla solver to solve a rather simple non-linear problem. In some cases there will be no feasible points for the problem. When I run even a simple problem where the non-feasibility is obvious, the solver return "Success" even though the solution is not feasible. Consider the following example, written in F#: open System.Collection.Generics let obj12 = QuadraticObjectiveFunction("a - a*a"); let c12 = QuadraticConstraint(obj12, Array2D.zeroCreate 1 1, [| 10.0 |],

F#: Member constraints to help create seemingly dynamic types

泄露秘密 提交于 2019-12-07 14:26:36
问题 I've been looking into a way to add some duck typing to an F# method. SomeMethod(model:'a) = let someField = model.Test("") Where the parameter coming in has the Test method on it. I've seen notation like this: member inline public x.Testing< ^a when ^a : (member public Test : String-> String)>(model:^a) = let something = model.Test("") ignore Which looks like to me that generic constraints can be used to enfore at a method level rather than class/interface level. Problem is I can't get it to

How to find the value in a list at which a maximum value of a function occurs

旧巷老猫 提交于 2019-12-07 14:26:24
问题 I want to find not just the maximum value of a function applied to a list (for which I would just use List.maxBy) but also the value in the list this occurred at. This feels like a fairly common operation and given the richness of the F# libraries in general I wouldn't be at all surprised to discover it was actually already available but I cannot seem to find it if it is! To illustrate with an example, I want to be able to map a list domain and a function f let domain = [0 .. 5] let f x = -x

Implementating functional languages for the CLR (Or, papers on the implementation of F#)

依然范特西╮ 提交于 2019-12-07 13:00:00
问题 Does anyone know of any good papers on the implementation of the F# compiler? I'm trying to generate CIL code for a simple functional language targeting the CLR, but I am struggling with a few aspects. The differences between functional languages and CIL are making it hard to generate well-typed CIL code. I have solutions that work via type erasure, but I'd much rather find a way to generate CIL code that reflects (to at least some extend) the Hindley-Milner type system of my source language

F# match with ->

寵の児 提交于 2019-12-07 12:44:37
问题 I want to make something like it (Nemerle syntax) def something = match(STT) | 1 with st= "Summ" | 2 with st= "AVG" => $"$st : $(summbycol(counter,STT))" on F# so is it real with F#? 回答1: If I understand you correctly, you'd like to assign some value to a variable as part of the pattern. There is no direct support for this in F#, but you can define a parameterized active pattern that does that: let (|Let|) v e = (v, e) match stt with | Let "Summ" (st, 1) | Let "AVG" (st, 2) -> srintf "%s ..."

How to avoid writing repetitive code for different numeric types in .NET

假装没事ソ 提交于 2019-12-07 12:04:07
问题 I am trying to write generic Vector2 type which would suite float, double, etc. types and use arithmetical operations. Is there any chance to do it in C#, F#, Nemerle or any other more or less mature .NET language? I need a solution with (1)good performance (same as I would have writing separate Vector2Float, Vector2Double, etc. classes), (2)which would allow code to look nice (I do not want to emit code for each class in run-time) (3)and which would do as much compile time checking as