mardi 22 décembre 2020

Random Function in Haskell

I'm currently working on a program in Haskell (which I am very new to) where I need to randomly generate co-ordinates and use them around the program in several places, however, I don't want to be threading IO around the whole program, nor the seed. I saw this link where they use num <- randomIO :: IO Float however I keep getting - Couldn't match type `IO' with `[]' Expected type: [Float]. I in theory need the co-ordinates to be integer values, so if there is a better way of doing it that would be great! The full stack is below:

Couldn't match type `IO' with `[]'
      Expected type: [Float]
        Actual type: IO Float
    * In a stmt of a 'do' block: y <- randomIO :: IO Float

Edit - here is a minimum reproducible example! I'm using stack as well.

import Data.List
import System.Random

main :: IO ()
main = 
    do
        xt <- randomIO :: IO Float
        x <- round ((xt) * (5))
        putStrLn x



Aucun commentaire:

Enregistrer un commentaire