在F#中至少有3种方法可以构建字符串:
我应该在F#中坚持哪一个?
F#对我来说并不容易.下面这段代码应该是一个列表.我不知道问题是什么.请帮忙.
let chunk items chunkSize =
let folder = fun state x ->
match state with (reversedResult, reversedChunk) ->
if reversedChunk.Length < chunkSize then
(reversedResult, x::reversedChunk)
else
((reversedChunk |> List.rev)::reversedResult, [x])
let alsmostDone = items |> List.fold folder ([], [])
match alsmostDone with
| (reversedResult, []) -> reversedResult |> List.rev
| (reversedResult, lastReversedChunk) -> (lastReversedChunk |> List.rev)::reversedResult |> List.rev
Run Code Online (Sandbox Code Playgroud)

我有2个控制器,都需要一个MySettings代表一组设置的对象.每个控制器都需要其自定义设置集.为了在模块注册时执行此操作,我手动创建了2个设置对象并将它们都放入容器中.问题是如何指定每个控制器应该注入自己的预定义的MySettings类型的自定义初始化实例?
更新:
现在有一个丑陋的解决方法,基本上使Autofac无用,因为所有解析都是手工完成的:
public class MyModule : Module {
protected override void Load(ContainerBuilder builder) {
builder.Register(context => {
var productControllerSettings = new MyListSettings(
pageSize: 20,
orderBy: "Name",
orderDirection: OrderDirection.Ascending
);
// and hell of other parameters that I need to resove
// by hands by doing context.Resolve<...> for each of them
var productController = new ProductController(
productControllerSettings
/*, the reset of parameters */
);
return productController;
});
builder.Register(context => {
var userControllerSettings = new MyListSettings {
pageSize: 20, …Run Code Online (Sandbox Code Playgroud) 我正在寻找一种方法来解决这个非常特殊的情况:我有一个函数工厂toF,它接受一个函数参数g并基于它创建一个结果函数f
let toF g =
let f x = g x
f
let f = toF id
Run Code Online (Sandbox Code Playgroud)
问题是我得到了
error FS0030: Value restriction. The value 'f' has been inferred to have generic type val f : ('_a -> '_a) Either make the arguments to 'f' explicit or, if you do not intend for it to be generic, add a type annotation.
Run Code Online (Sandbox Code Playgroud)
我可以添加类型注释(我不急于做)或者我可以像这样重写它:
let f' g x = g x
let f x = f' id x …Run Code Online (Sandbox Code Playgroud) 我需要拉链列表.我不知道如何将它与我的项目联系起来.文档页面没有多说:http://hackage.haskell.org/package/ListZipper-1.2.0.1/docs/Data-List-Zipper.html
你能帮忙吗?
我需要一种有效的方法来测试给定字符(System.Char)作为辅音.然后我对元音需要同样的东西.更一般地说,我需要有效实现以下接口,因为目标字符集大约有20个字符.请指教.谢谢!
using System;
public interface ITester
{
Boolean IsInCategory(Char something);
}
Run Code Online (Sandbox Code Playgroud)
UPDATE
好的,我已经进行了一些测试.这就是我得到的.最好的方法是使用预先计算的映射,其中每个char都映射到布尔值.(参见下面代码中的IndexBased).事实证明,HashSet并不是最好的.如果有人有更多的想法,请告诉我.
[TestClass]
public class Runner
{
public const Int32 NumberOfRuns = 10000;
public const String TextSample = @"The Letter It was November. Although it was not yet late, the sky was dark when I turned into Laundress Passage. Father had finished for the day, switched off the shop lights and closed the shutters; but so I would not come home to darkness he had left on the light …Run Code Online (Sandbox Code Playgroud) 我有一个实现 INavigationAware 接口的视图。该接口具有 OnNavigationFrom 方法,即根据 MSDN http://msdn.microsoft.com/en-us/library/microsoft.practices.prism.regions.inavigationaware.onnavigatedfrom(v=pandp.40).aspx,
当实现者被导航离开时调用。
现在,我想确保用户没有留下任何未保存的更改,如果有未保存的更改,请询问用户是否要保存它们。此时,我需要能够以某种方式取消该导航请求,以防用户想留下来继续编辑。
MSDN 上有关 INavigationAware 接口的文档没有说明应该如何使用该接口。
我可能是大错特错了,没有办法取消它,或者这个界面不适合那个。
无论如何,如果有人告诉我如何让用户留下并继续编辑已启动的导航请求,我将不胜感激。
我试图根据自定义At类型类定义一个简单的文本游标,如下所示:
{-# LANGUAGE MultiParamTypeClasses #-}
class At a b where
valueAt :: a -> b
moveOn :: a -> Maybe a
newtype AtText = AsAtText [Char] deriving (Show)
instance At AtText Char where
valueAt (AsAtText []) = error "Unable to get a value from an empty list."
valueAt (AsAtText (x:_)) = x
moveOn (AsAtText []) = Nothing
moveOn (AsAtText [_]) = Nothing
moveOn (AsAtText (_:xt)) = Just $ AsAtText xt
Run Code Online (Sandbox Code Playgroud)
到目前为止这么好,我碰到的问题是我moveOn后来尝试在代码中使用该方法.所以编译器说它无法推断出应该使用哪个确切的实例来要求我提供签名.
No instance for (At AtText …Run Code Online (Sandbox Code Playgroud) 我需要压缩相同类型的可枚举枚举数.在FP中它将是一个标准函数concat(http://msdn.microsoft.com/en-us/library/ee353462.aspx).我在C#(Linq)做什么?