0

I'm generating a minesweeper board and want to generate the board based on where the first click (actually not a click, just a string written in the cmd representing a click) was done. This is a problem though, as I have to mix the Gen and IO monad. Is there a way to convert Gen a to IO a?

I found this function. Which would do exactly what i want. But it isn't available for import.

SiXoS
  • 535
  • 3
  • 14
  • I realised that I can use sample' :: Gen a -> IO [a] and take the first result. But that is a bit of an ugly hack. – SiXoS Dec 10 '14 at 10:13
  • @Sibi It is a monad from the QuickCheck module, source here: [link](http://hackage.haskell.org/package/QuickCheck-2.7.6/docs/src/Test-QuickCheck-Gen.html#Gen) – SiXoS Dec 10 '14 at 10:15
  • It is available for import. Just `import Test.QuickCheck.Gen`. – András Kovács Dec 10 '14 at 10:25
  • @András Kovács It's not, I have tried. You can't even find it in Hoogle. But I've found out a answer now, coming up soon. – SiXoS Dec 10 '14 at 10:27
  • It is a function from the public interface of that package. The package in fact exports everything it defines. If you are not able to import it, there's a bug somewhere. Perhaps you are using a wrong version. Show your error messages. – n. m. could be an AI Dec 10 '14 at 10:28
  • 1
    @SiXoS I just imported it in my ghci from my QuickCheck 2.7.6. – András Kovács Dec 10 '14 at 10:29
  • 1
    @SiXoS: It's on the first page of FP Complete Hoogle! https://www.fpcomplete.com/hoogle?q=generate – Tom Ellis Dec 10 '14 at 10:45
  • @AndrásKovács @n.m. @Tom Ellis How do i check the QuickCheck version? When I import Test.QuickCheck.Gen(generate): Module `Test.QuickCheck.Gen' does not export `generate' – SiXoS Dec 10 '14 at 14:43
  • @SiXoS `ghc-pkg list` on the terminal is one way to do it. – András Kovács Dec 10 '14 at 17:57

1 Answers1

2

I realised that using Gen was a bad idea and are now using StdGen instead

This is not only more practical in my case but also generates a better randomness

SiXoS
  • 535
  • 3
  • 14