小编Tri*_*Gao的帖子

如何在C#中创建真正不可变的双向链表?

这更像是一个理论问题:C#中是否有可能创建一个真正不可变的双向链表?我看到的一个问题是2个相邻节点的相互依赖.

"真正"我指的是使用只读字段.

c# language-features data-structures

6
推荐指数
1
解决办法
1156
查看次数

INotifyDataErrorInfo.GetErrors应返回什么类型的IEnumerable?

我想到MSDN上的官方文档没有说明由INotifyDataErrorInfo的GetErrors返回的可枚举的底层对象类型应该是什么:http://msdn.microsoft.com/en-us/library/system .componentmodel.inotifydataerrorinfo.geterrors(v = VS.95)的.aspx

选项包括:System.String,System.Object,MyCustomObject,ISomeOtherShitThatDoesntHaveAnythingToDoWithValidationWhatever

任何人都可以向我解释一个任意的可枚举对象如何在不对其结构做出任何假设的情况下通知错误吗?

silverlight-4.0

6
推荐指数
1
解决办法
640
查看次数

如何附加到F#中的列表而不是前置?

在F#中列出一个列表有点烦人,因为一旦你完成了你必须扭转它.有没有办法从一开始就建立一个列表?

f#

6
推荐指数
2
解决办法
1441
查看次数

如何将带有派生类型参数的委托转换为具有基类型参数的委托?

考虑一下代码:

public interface IGeneral {}
public interface ISpecific : IGeneral {}
public Func<IGeneral, String> Cast(Object specificFuncAsObject) {
      var generalFunc = specificFuncAsObject as Func<IGeneral, String>;
      Assert.IsNotNull(generalFunc); // <--- casting didn't work
      return generalFunc;
}

Func<ISpecific, String> specificFunc = specific => "Hey!";
var generalFunc = Cast(specificFunc);
Run Code Online (Sandbox Code Playgroud)

有没有办法让这种铸造工作?我知道在一般情况下,IGeneral无法投放到ISpecific.但在我的特殊情况下,我希望我能做到这样的事情:

 Func<IGeneral, String> generalFunc = new Func<IGeneral, String>(general => specificFunc(general as ISpecific));
Run Code Online (Sandbox Code Playgroud)

但是具有specificFuncas Object并且ISpecific只有via类型specificFuncAsObject.GetType()

c#

6
推荐指数
2
解决办法
1098
查看次数

为什么没有Seq.rev功能?

对我来说这看起来像是一个复杂的问题.为了反转序列(可枚举),必须首先将其转换为列表.这是为什么?

f#

6
推荐指数
2
解决办法
847
查看次数

除了使用访问者模式之外,有没有办法在C#中使用变体?

在C#中没有对变体类型(也称为标记的联合,区分联合)的直接支持.然而,人们可以使用访问者模式,通过双重调度实现歧视,并保证在编译时解决所有情况.然而,实施起来很繁琐.我想知道是否有更容易获得的方法:某种具有歧视机制的变体可以保证在C#的编译时解决所有联合的情况?

// This is a variant type. At each single time it can only hold one case (a value)
// from a predefined set of cases. All classes that implement this interface
// consitute the set of the valid cases of the variant. So at each time a variant can
// be an instance of one of the classes that implement this interface. In order to
// add a new case to the variant there …
Run Code Online (Sandbox Code Playgroud)

c# variant visitor-pattern

6
推荐指数
1
解决办法
954
查看次数

为什么我的顶级函数需要在Haskell中签名?

GHC警告我在顶层没有功能签名.我不明白为什么我会需要它们.提供它们的问题是它们非常复杂,就像这个(自动生成):

applyValue :: forall t t1 t2 t3 t4.
                (t2 -> t)
                -> (t2 -> t3 -> t4 -> t1) -> t2 -> t3 -> t4 -> (t -> Bool) -> [t1]
Run Code Online (Sandbox Code Playgroud)

那么我为什么还要加入呢?

功能本身:

applyValue getValueAt stitchAndMove at fabric mark matchAt =
   if matchAt (getValueAt at)
   then [stitchAndMove at fabric mark]
   else []
Run Code Online (Sandbox Code Playgroud)

haskell

6
推荐指数
1
解决办法
1045
查看次数

newtype如何帮助隐藏任何东西?

现实世界haskell说:

我们将使用newtype声明隐藏解析器类型的细节

我不知道如何使用newtype隐藏任何东西.谁能详细说明?我们试图隐藏什么,我们如何做到这一点.

data ParseState = ParseState {
  string :: L.ByteString
, offset :: Int64           -- imported from Data.Int
} deriving (Show)


newtype Parse a = Parse {
    runParse :: ParseState -> Either String (a, ParseState)
}
Run Code Online (Sandbox Code Playgroud)

haskell

6
推荐指数
2
解决办法
269
查看次数

有没有办法连接到TypeScript编译器并根据TypeScipt代码模型发出一些自定义JavaScript代码?

我想知道我是否可以以某种方式扩展或连接到TypeScript编译器并根据我的代码中TypeScript接口的声明生成一些函数.基本上,这些函数将验证来自服务器的数据对象是否符合对象应该实现的TypeScript接口.我想有一个特殊的接口标记,我希望我的编译器的钩子是由这样的接口触发的.一旦检测到该标记接口,我将分析该接口的成员并生成将根据该接口定义的数据协定验证给定对象的代码.有没有办法做到这一点?有人可以给点指示吗?

typescript

6
推荐指数
2
解决办法
1339
查看次数

是否有一个标准的Haskell函数,它为函数添加了一个额外的参数

我有一个功能a->b,将被传递给(c->a->b)签名的东西.我不在乎c只会忽略它.是否有一个标准函数可以预先设置无用的参数:(a->b) -> (c->a->b)

haskell

6
推荐指数
1
解决办法
100
查看次数