-
-
Save dom96/513429 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
*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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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