0
我使用Control.Monad.Rand
,我有一個結構將Rand monad帶出`data`構造?
data MCSystem = MCSystem { params :: Params
, path :: Path }
和功能,我不知道如何實現 -
runSystem :: (RandomGen g) => MCSystem -> Rand g MCSystem
runSystem system = MCSystem mcparams newPath -- this line doesn't make any
-- sense and i know it
where
mcparams = params system
newPath = runPath $ path system
runPath :: (RandomGen g) => Path -> Rand g Path
-- basically performs a random mutation on the path
runPath
返回Rand g Path
單子......如何我是否需要將它作爲新的Rand g MCSystem
monad,以便runSystem
能夠正確返回它,並且稍後可以使用生成器來調用它?
我想也許我可以重構一個閱讀器monad的一切,但我覺得我想避免它,如果可能的話。
我覺得有點傻,我實際上在程序的另一部分中使用了符號方法,但在這種情況下,我是「重構」以隨機添加,並且被我已經寫入的函數式樣蒙上了一層陰影。 –
但在某種程度上,應用風格似乎更具表現力。你有沒有什麼好的參考來開始適用於程序設計? –
一個很好的指導是在學習你一個haskell教程中的[Functors,Applicative Functors和Monoid章節](http://learnyouahaskell.com/functors-applicative-functors-and-monoids)。 –