我製作迷宮發生器並希望通過打印形象化迷宮。我有一個牆型和一個隨機生成這些牆的迷宮的功能。製作Monad類型可顯示
import qualified Data.Graph.Inductive as Graph
import Data.Graph.Inductive (Gr, prettyPrint)
data WeightedWall = WeightedWall (Int, Int, Int) Orientation deriving (Eq)
weightedGrid :: MonadRandom m => Int -> Int -> Gr() (m WeightedWall)
然而,當我打電話prettyPrint(weightedGrid 10 10)
,我得到這個錯誤:
Ambiguous type variable ‘m0’ arising from a use of ‘prettyPrint’
prevents the constraint ‘(Show
(m0 WeightedWall))’ from being solved.
Probable fix: use a type annotation to specify what ‘m0’ should be.
什麼我在我的代碼所缺少解決這一問題?
'MonadRandom'你想'什麼M'是? – 4castle
我是Haskell的新手,我不確定它應該是什麼。 weightedGrid中注入隨機性的函數是Control.Monad.Random中的getRandomR(如果有幫助)。 – chronologos
'm'的一些可能的值是['Rand'](http://hackage.haskell.org/package/MonadRandom-0.5.1/docs/Control-Monad-Trans-Random-Lazy.html#t:蘭特)或'IO'。編譯器不知道要使用哪一個,除非你給'weightedGrid'調用的結果賦予一個類型註釋。 – 4castle