私が書いた関数は、他の機会にもうまく使用していますが、動作していないことに気付きました。'next'を使用してarivingするインスタンスがありません
私のテストファイル(ちょうどこの問題をテストするために作られたもの)は次のようになります。
import System.Random
generator = next . snd
これは奇妙なことがあれば、私はGHCiのとタイプを開くことで、エラー
No instance for (RandomGen g0) arising from a use of ‘next’
The type variable ‘g0’ is ambiguous
Relevant bindings include
generator :: (a, g0) -> (Int, g0) (bound at Test.hs:2:1)
Note: there is a potential instance available:
instance RandomGen StdGen -- Defined in ‘System.Random’
In the first argument of ‘(.)’, namely ‘next’
In the expression: next . snd
In an equation for ‘generator’: generator = next . snd
になり:
import System.Random
let generator = next . snd
すべてがうまくいきます。私は何が欠けているのですか?
編集:また、これを試してみましたし、それだけで正常に動作します:
generator something = next (snd something)
あなたは[Monomorphism Restriction Instance](https://wiki.haskell.org/Monomorphism_restriction);)を見つけたので、GHCiで ':set -XMonomorphismRestriction'を実行すると同じ結果が得られます – Carsten