这是一个非常简单的问题,但我找不到答案:
在F#中是否有任何Seq/List操作来匹配LINQ SelectMany?
但是,如果我试图证明F#List操作比LINQ更强大......
在C#SelectMany使用语法非常简单:
var flattenedList = from i in items1
from j in items2
select ...
Run Code Online (Sandbox Code Playgroud)
有没有简单的直接匹配,List.flatten,List.bind或类似的东西?
SelectMany有几个签名,但最复杂的签名似乎是:
IEnumerable<TResult> SelectMany<TSource, TCollection, TResult>(
this IEnumerable<TSource> source,
Func<TSource, IEnumerable<TCollection>> collectionSelector,
Func<TSource, TCollection, TResult> resultSelector
);
Run Code Online (Sandbox Code Playgroud)
在F#术语中,这将是:
('a -> 'b list) -> ('a -> 'b -> 'c) -> 'a list -> 'c list
Run Code Online (Sandbox Code Playgroud) Microsoft已发布Javascript的Reactive Extensions.它应该使异步(和基于事件的)web-ui编程变得容易.
我有一个包含 ASP.NET 网站的解决方案文件。
当我使用 .NET 4.0 Beta 2 构建解决方案时
"c:\WINDOWS\Microsoft.NET\Framework\v4.0.21006\MSBuild.exe" d:\MyPath\MySolution.sln
一切正常,没有错误。然后我尝试使用 CruiseControl .NET 任务(由服务运行的 msbuild-script)构建相同的解决方案,相同的解决方案失败了:
D:\MyPath\MyWebSite.metaproj (,): errorMSB4025: 无法加载项目文件。找不到文件“D:\MyPath\MyWebSite.metaproj”。
当然,没有这样的文件。我猜 *.metaproj 是一个类似 .csproj 的 msbuild 文件,它是为网站动态生成的...
但我不知道如何修复错误......我试图谷歌元数据文件但没有运气。我确实尝试手动制作文件,我插入了一个带有 <Task Name="Rebuild"> 的 <Project> 并且编译没有引发任何错误,但我猜该站点没有编译。
同一台机器有 .NET 3.5 和 .NET 4.0 项目以及两个框架的环境变量。
cruisecontrol.net msbuild vs-web-site-project asp.net-4.0 web
不再使用时,我应该明确清除非全局 ConcurrentDictionary,还是 GC 检测到它不再使用?
这有点相关:ConcurrentBag 是内存泄漏的原因吗?
编辑:我问的原因是,我有以下代码(此处简化):
let myMethod() =
async {
let myEventList = ConcurrentDictionary<myEventParams, bool>()
use o = myEvent |> Observable.subscribe(fun e ->
myEventList.GetOrAdd(e, true) |> ignore)
let! res = doAsyncThingsCausingEvents()
myEventList |> Seq.iter(fun (e,_) -> Console.WriteLine "We had " + e.ToString())
res
}
Run Code Online (Sandbox Code Playgroud)
...实际上它在多个线程中多次并行调用时会泄漏内存。
我想知道为什么F-Sharp不支持无限.
这适用于Ruby(但不适用于f#):
let numbers n = [1 .. 1/0] |> Seq.take(n)
Run Code Online (Sandbox Code Playgroud)
- > System.DivideByZeroException:尝试除以零.
我可以用非常复杂的方式编写相同的功能:
let numbers n = 1 |> Seq.unfold (fun i -> Some (i, i + 1)) |> Seq.take(n)
Run Code Online (Sandbox Code Playgroud)
- >工作
但是我认为第一个会更清楚.我找不到在F#中使用动态类型无穷大的任何简单方法.有无限关键字,但它是浮点数:
let a = Math.bigint +infinity;;
Run Code Online (Sandbox Code Playgroud)
System.OverflowException:BigInteger不能表示无穷大.at System.Numerics.BigInteger..ctor(Double value)at.$ FSI_0045.main @()因错误而停止
编辑:这似乎也适用于迭代:
let numbers n = Seq.initInfinite (fun i -> i+1) |> Seq.take(n)
Run Code Online (Sandbox Code Playgroud) ASP.NET Web站点随机引发此System.Drawing-error:
System.Runtime.InteropServices.ExternalException:System.Drawing.Bitmap..ctor(Stream stream)System.Drawing.ToolboxBitmapAttribute..cctor()
Exception information:
Exception type: TypeInitializationException
Exception message: The type initializer for 'System.Drawing.ToolboxBitmapAttribute' threw an exception.
Stack trace: at System.Reflection.CustomAttribute._CreateCaObject(Void* pModule, Void* pCtor, Byte** ppBlob, Byte* pEndBlob, Int32* pcNamedArgs)
at System.Reflection.CustomAttribute.CreateCaObject(Module module, RuntimeMethodHandle ctor, IntPtr& blob, IntPtr blobEnd, Int32& namedArgs)
at System.Reflection.CustomAttribute.GetCustomAttributes(Module decoratedModule, Int32 decoratedMetadataToken, Int32 pcaCount, RuntimeType attributeFilterType, Boolean mustBeInheritable, IList derivedAttributes)
at System.Reflection.CustomAttribute.GetCustomAttributes(RuntimeType type, RuntimeType caType, Boolean inherit)
at System.RuntimeType.GetCustomAttributes(Type attributeType, Boolean inherit)
at System.ComponentModel.ReflectTypeDescriptionProvider.ReflectGetAttributes(Type type)
at System.ComponentModel.ReflectTypeDescriptionProvider.ReflectedTypeData.GetAttributes()
at System.ComponentModel.TypeDescriptor.TypeDescriptionNode.DefaultTypeDescriptor.System.ComponentModel.ICustomTypeDescriptor.GetAttributes()
at System.ComponentModel.TypeDescriptor.GetAttributes(Type componentType)
at System.Web.UI.ThemeableAttribute.IsTypeThemeable(Type …Run Code Online (Sandbox Code Playgroud) 历史上操作系统目录结构是树:
REST架构模拟同样的事情:
但是,看看当前的结构,我需要进行搜索:
使用每个树层次结构组合执行REST接口效率不高.您需要更有效的信息管理; 你需要一个属性系统而不是树形结构.(哦,为什么操作系统不是基于属性?)
StackOverflow和Google似乎使用属性和语法"+" - 标记如下:
今天的框架如WCF和ASP.NET MVC对RESTful树结构有很好的支持.但是对属性结构有支持吗?难道你不会将属性结构称为REST吗?
我想创建一个属性-WebService并将其与Silverlight-client中的LINQ一起使用...哪种方法最好?:-)
我如何解决河内塔问题的运行时间.我得到一个像t(n)= 2t(n-1)+ 1的递归反射.绘制递归树后,我得到每一步的值,如1 + 2 + 4 + 8 ...树的高度将是lg (N).我如何计算系列的总和?我什么时候停止?
f# ×4
.net ×1
algorithm ×1
asp.net ×1
asp.net-4.0 ×1
attributes ×1
c# ×1
gdi+ ×1
iis ×1
infinity ×1
javascript ×1
lazylist ×1
linq ×1
memory-leaks ×1
msbuild ×1
oop ×1
rest ×1
web ×1
web-services ×1