私はタイプを持っています
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