我制作迷宫发生器并希望通过打印形象化迷宫。我有一个墙型和一个随机生成这些墙的迷宫的功能。制作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