我有一个类型
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]
我的主要问题是:如何在特定变量中定义变量PolyRing
?
它应该是这样的:
x = [1, 2, 3] :: Integer T5
(我认为)问题是: 之后的正确语法是::
什么?
我收到错误
Couldn't match expected type `PolyRing Integer T5'
with actual type `[t0]'
In the expression: [1, 2, 3] :: PolyRing Integer T5
In an equation for `x': x = [1, 2, 3] :: PolyRing Integer T5
另外,我正在寻找一种更好的方法来实现这一点。特别是,我真的希望a
从列表元素的类型中推断出类型,而IntegerAsType n
必须指定(它不应该取决于列表的长度,即使这是可能的)。
到目前为止我尝试过的事情:
x = [1,2,3] :: PolyRing (Integer, T5)
x = [1,2,3] :: PolyRing Integer T5