type-constraints

    8热度

    1回答

    基本上,给定{-# LANGUAGE PolymorphicKinds, ConstraintKinds, TypeFamilies #-}(以及更多,如有必要),(~)类型级别的操作符是否可以处理类型为Constraint的表达式?我试着用Google搜索答案,但没有运气。

    0热度

    2回答

    我有一个abstract类,它有一个类型约束。但我也想让abstract类实现一个接口。 E.g: public abstract class PostEvent<TPost> : IDomainEvent, where TPost : Post, new() 根本不能编译。因为这意味着TPost : IDomainEvent public abstract class PostEvent<T

    0热度

    2回答

    我想在mongoid中创建一个embeds_many关系,它似乎没有对我添加到集合的对象强制执行类型约束。我在这里做了些什么不正确的事情还是这个设计? class Item include Mongoid::Document embeds_many :extra_fields, class_name: "ItemType" end class ItemType

    2热度

    2回答

    可能重复: Create Generic method constraining T to an Enum 鉴于只有在枚举操作的一般方法值 static void <T> method(T enum) where T ????? { // do something with enum... } 如何我是否限制T这样只有枚举值被接受?我试过使用struct,但是这不允许使用可空的枚

    4热度

    1回答

    我正在做一个有趣的项目,我试图从Java中重做一些基本数据类型和概念。目前我正在处理迭代器。 我的方法如下: (1)翻译接口到类型类 (2)声明的自定义数据类型和实例对于实际的实现 因此,我创建以下类型的类: class Iterator it where next :: it e -> (it e, e) hasNext :: it e -> Bool class Ite

    2热度

    2回答

    我在一个WPF应用程序中有一个DataGrid,它的ItemsSource是我写的一个自定义集合。该集合强制其所有项目都满足特定要求(即它们必须介于某些最小值和最大值之间)。 集合的类签名是: public class CheckedObservableCollection<T> : IList<T>, ICollection<T>, IList, ICollection,

    3热度

    4回答

    我试图定义一个通用除了运营商的包装类。到目前为止,我有这样的:(从实际代码的简化) type Wrap<'a> = | Wrap of 'a static member inline (+) (Wrap x, Wrap y) = Wrap (x + y) let inline addSelf x = x + x ,实际上它的工作原理: let i = addSelf (

    7热度

    2回答

    考虑下面的代码: class Base<T> { //Base members } 我想通用吨至是一个枚举(如果可能的话使用约束)。我怎样才能在C#中做到这一点? 编辑: 通过阿卡什Kava- -introduced使用代码合同也似乎是一个很好的方式。我设法让它产生一个无用的运行时错误。 Here是我试过的代码。应该可以生成编译时警告,但我无法使其工作。

    8热度

    2回答

    所以我读Eric Lippert's 'Constraints are not part of the signature',现在我明白规范指定在重载解析后检查类型约束,但我仍不清楚为什么必须如此。下面是Eric的例子: 这不会编译因为重载解析:Foo(new Giraffe())推断Foo<Giraffe>是最好的超负荷比赛,但随后的类型约束失败和编译时错误被抛出。用埃里克的话来说: 这里的原则

    2热度

    2回答

    我有一个通用的接口, public interface ICalculator<in T> { void Calculate(T input); } 一般的计算器, public class GeneralCalculator<T> : ICalculator<T> { public void Calculate(T input)