Skip to content

Instantly share code, notes, and snippets.

@duckinator
Created August 8, 2010 01:10
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save duckinator/513418 to your computer and use it in GitHub Desktop.
Save duckinator/513418 to your computer and use it in GitHub Desktop.
*Main> :l markov.hs
[1 of 1] Compiling Main ( markov.hs, interpreted )
Ok, modules loaded: Main.
*Main> let x = markovChain 1 5
<interactive>:1:8:
No instances for (Num (IO b), Ord (IO b))
arising from a use of `markovChain' at <interactive>:1:8-22
Possible fix:
add an instance declaration for (Num (IO b), Ord (IO b))
In the expression: markovChain 1 5
In the definition of `x': x = markovChain 1 5
*Main>
import System.Random
--randomNegate :: (Integral a) => a -> IO a
--markovMain :: (Integral a) => a a -> [a a]
--markovChain :: (Integral a) => a a -> [a a]
randomNegate magnitude = do
rand <- randomIO :: IO Bool
if rand
then negate magnitude
else magnitude
markovMain initial range n = do
let up_or_down = randomNegate 1
let n = n + up_or_down
if (n > (initial + range)) || (n < (initial - range))
then [n, up_or_down]
else markovMain initial range n
-- markovMain expects `initial range n`, but n starts at initial
markovChain initial range = markovMain initial range initial
--main = do
-- print markovChain 1 5
{--
while true
up_or_down = randomNegate()
if !n
n = initial
else
n += up_or_down
end
if (n > (initial + range)) || (n < (initial - range))
[n, up_or_down]
end
end
--}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment