Ugh... Struggling with haskell. Trying to implement Conway's GOL and create a random game board. Here is where I am at.
I have a function to randomize each square in an array, and a function to create an array of characters using the randomization function to represent my game board.
I am trying to now create a function: showBoard, which iterates through the array and concatenates each char to a string which I can print out in my main.
import System.Random
import Control.Monad
import Data.Array
import Data.List
randomBoard = do
f1 <- randomIO :: IO Int
if(f1 `mod` 2) == 0
then return '*'
else return ' '
boardArray :: IO (Array Int Char)
boardArray = listArray (0, 99) <$> replicateM 100 randomBoard
showBoard :: IO (Array Int Char) -> Int -> String -> String
showBoard arr i str = do
if i > 0
then showBoard arr (i-1) (str ++ (arr ! i))
else return str
main :: IO ()
main =
let board = showBoard boardArray 100 ""
in
do
putStr board
I have spent an hour trying to tweak this out and keep getting type issues. I cant even get this board to print x.x please help.