我想定义一个事物的几个版本,但是使用不同的类型来增强我的程序中的类型安全性。例如,我有几种类型的双变量值,我想要成为Num的实例,但所有变量都应该是不同的类型。所以我所做的就是用一个类型变量创建一个新类型并基于此类型声明新类型。然而,我觉得现在不得不一直使用这两个构造函数,这有点令人讨厌。有没有办法解决? {-# LANGUAGE GeneralizedNewtypeDeriving #-}
例如,ParsecT在其定义中有多个类型变量。 newtype ParsecT s u m a
= ParsecT {unParser :: forall b .
State s u
-> (a -> State s u -> ParseError -> m b)
-> (ParseError -> m b)
->
我有一个类型 class IntegerAsType a where
value :: a -> Integer
data T5
instance IntegerAsType T5 where value _ = 5
newtype (Num a, IntegerAsType n) => PolyRing a n = PolyRing [a]
我环顾四周,换一种方式来指定N
我想我明白斯卡拉2.10的新的“值类”功能,通过与Haskell的newtype比较: trait BoundedValue[+This] extends Any { this: This =>
def upperBound: This
def lowerBound: This
}
class Probability @throws(classOf[IllegalA
由于newtype在编译过程中被有效移除,所以它们没有thunk,只是值。那么如果我使用rseq来询问其WHNF会发生什么?例如,在 Sum (lengthyComputation :: Int) `using` rseq
其中Sum定义为 newtype Sum a = Sum { getSum :: a }
将lengthyComputation得到评估或不?是否在某处指定/记录,以便
我有这样的说法: newtype State st a = State (st -> (st, a))
。因此State类型是: State :: (st -> (st, a)) -> State st a
我不明白其中的含义: 是st和a只是两个数据类型的占位符?对? 该声明是否意味着State是一个函数,它作为一个函数的参数?