这更像是一个理论问题:C#中是否有可能创建一个真正不可变的双向链表?我看到的一个问题是2个相邻节点的相互依赖.
"真正"我指的是使用只读字段.
我想到MSDN上的官方文档没有说明由INotifyDataErrorInfo的GetErrors返回的可枚举的底层对象类型应该是什么:http://msdn.microsoft.com/en-us/library/system .componentmodel.inotifydataerrorinfo.geterrors(v = VS.95)的.aspx
选项包括:System.String,System.Object,MyCustomObject,ISomeOtherShitThatDoesntHaveAnythingToDoWithValidationWhatever
任何人都可以向我解释一个任意的可枚举对象如何在不对其结构做出任何假设的情况下通知错误吗?
考虑一下代码:
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#中没有对变体类型(也称为标记的联合,区分联合)的直接支持.然而,人们可以使用访问者模式,通过双重调度实现歧视,并保证在编译时解决所有情况.然而,实施起来很繁琐.我想知道是否有更容易获得的方法:某种具有歧视机制的变体可以保证在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) 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说:
我们将使用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) 我想知道我是否可以以某种方式扩展或连接到TypeScript编译器并根据我的代码中TypeScript接口的声明生成一些函数.基本上,这些函数将验证来自服务器的数据对象是否符合对象应该实现的TypeScript接口.我想有一个特殊的接口标记,我希望我的编译器的钩子是由这样的接口触发的.一旦检测到该标记接口,我将分析该接口的成员并生成将根据该接口定义的数据协定验证给定对象的代码.有没有办法做到这一点?有人可以给点指示吗?
我有一个功能a->b,将被传递给(c->a->b)签名的东西.我不在乎c只会忽略它.是否有一个标准函数可以预先设置无用的参数:(a->b) -> (c->a->b)?