Skip to content

Instantly share code, notes, and snippets.

@dom96
Forked from duckinator/markov.hs
Created August 8, 2010 01:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save dom96/513429 to your computer and use it in GitHub Desktop.
Save dom96/513429 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 return $ negate magnitude
else return magnitude
markovMain initial range n = do
up_or_down <- randomNegate 1
let n1 = n + up_or_down
if (n1 > (initial + range)) || (n1 < (initial - range))
then return [n1, up_or_down]
else markovMain initial range n1
-- 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