自分のモナドを作りたいです。これは私が書いたものです:
data LeafConType a = LeafCon (a,Int,Int)
instance Monad (LeafConType ) where
return = LeafCon
lc@(LeafCon (t,i,n)) >>= f = if i>=n
then lc
else f (t,i,n)
しかし、これは機能しません。Ghcは言う:
leafcon.hs:26:1:
Occurs check: cannot construct the infinite type: a = (a, Int, Int)
When generalising the type(s) for `return'
In the instance declaration for `Monad LeafConType'
leafcon.hs:27:1:
Occurs check: cannot construct the infinite type: a = (a, Int, Int)
When generalising the type(s) for `>>='
In the instance declaration for `Monad LeafConType'
それのどこが悪いんだい?
iがnより低いときに計算をしたい。nは定数である必要があります。これを正しく行う方法はまだわかりません。それは州と多分のいくつかの組み合わせでなければなりません。何かアドバイスがあれば、遠慮なく私と共有してください:P