typeclass

    0热度

    5回答

    *User> :t sqrt sqrt :: Floating a => a -> a 我不明白Floating a => a -> a想告诉我什么。我的教授告诉我sqrt可以认为是sqrt :: Double -> Double 它的确如此,但Floating a => a -> a是什么意思? 谢谢

    0热度

    1回答

    我希望能够说的是一个A的所有类型它们也是B class A g where f :: g -> Int class B g where h :: g -> Int instance A g => B g where h = f 我得到的编译错误: Illegal instance declaration for `B g' … (All ins

    0热度

    1回答

    sealed trait FormField case class StringField(name: String, value: String) extends FormField case class ChoiceField[T : Writes](name: String, value: T, choices: List[T]) extends FormField 然后,别的地方我

    0热度

    1回答

    我使用Scala的枚举类型与游戏框架的读取和写入组合。我想有一个像特点: trait EnumerationWrites[T <: Enumeration] { def reads(jsonValue: JsValue): JsResult[T] = jsonScope match { case JsString(s) => JsSuccess(T.withName(s)) <

    6热度

    3回答

    以下示例是我现实生活问题的简化版本。它似乎在某种程度上类似于Retrieving information from DataKinds constrained existential types,但我无法完全得到我正在寻找的答案。 假设我们有一个有限的,晋升DataKind K与类型A和B,和聚kinded Proxy数据类型,产生与各类样的条件*。 {-# LANGUAGE DataKinds,

    7热度

    1回答

    我偶然发现了以下小问题。我使用哈斯克尔记录语法,连同GADTs: {-# LANGUAGE GADTs #-} data Test a where Test :: {someString :: String, someData :: a} -> Test a 现在我想用不同类型someData创建一个新的Test值,但someString(相同的值来证明记录更新语法的用法): t

    1热度

    1回答

    这是我的第一个问题,所以我希望我能够正确地做所有事情。 我的情况是这样的:我想使用类型类来表示特定类型在函数下关闭。具体而言,类型类别被称为Substitutable。目的是如果T是Substitutable的一个实例,那么您可以对其应用替代并获得T作为回报。这是通过的每个实例必须实现的方法applySubstitution来实现的。 集合继承此闭包属性;如果我将元素替换应用于列表T s,其中T是

    5热度

    3回答

    在斯卡拉通用更新功能的工作,我需要创建一个产品类型&代表一个复合值,例如: val and: String & Int & User & ... = ??? 即and应该有一个String部分和一个Int部分和User部分里面。这类似于斯卡拉with关键字: val and: String with Int with User with ... = ??? 有这样的产品类型,我需要一种方法

    0热度

    1回答

    我有以下类型类: trait Loader[A, B, C] { //Any Spark loader requires // A -> Input Type // B -> Output Type // C -> some type of implicit context provided by the compiler from // the

    7热度

    2回答

    我想用类型系列来表示表达式,但我似乎无法弄清楚如何编写我想要的约束,并且我开始觉得它是不可能的。这里是我的代码: class Evaluable c where type Return c :: * evaluate :: c -> Return c data Negate n = Negate n instance (Evaluable n, Return n ~ I