Skip to content
Snippets Groups Projects
Commit e882125f authored by Janne Sirviö's avatar Janne Sirviö :hushed:
Browse files

Initial version

parent 77c08657
No related branches found
No related tags found
No related merge requests found
module Main where
import Control.Monad
import Lib
main :: IO ()
main = someFunc
main = do
putStrLn "How many random integer numbers should we generate?"
count <- read <$> getLine :: IO Int
putStrLn "What would be the minimum value of those numbers?"
min <- read <$> getLine :: IO Int
putStrLn "What would be the maximum value of those numbers?"
max <- read <$> getLine :: IO Int
if count <= 0 then error "The count must be a positive number"
else if max < min then error "The minimum cannot be larger than the maximum"
else putStrLn $ "Very well, producing " ++
(if count == 1 then "a number" else show count ++ " numbers") ++
" between " ++ show min ++ " and " ++ show max ++ "!"
putStrLn $ "In real life, we could emulate that with " ++
show count ++ " x " ++
show (max-min+1) ++ " sided dice rolls."
forM_ [1..count] (generateNumber min max)
......@@ -21,6 +21,7 @@ description: Please see the README on GitHub at <https://github.com/gith
dependencies:
- base >= 4.7 && < 5
- random >= 1.1
library:
source-dirs: src
......
module Lib
( someFunc
( generateNumber
) where
someFunc :: IO ()
someFunc = putStrLn "someFunc"
import System.Random (randomRIO)
generateNumber:: Int -> Int -> Int -> IO ()
generateNumber min max n = do
number <- randomRIO (min, max) -- :: IO Integer
putStrLn $ "The number " ++ show n ++ " is " ++ show number
......@@ -4,7 +4,7 @@ cabal-version: 1.12
--
-- see: https://github.com/sol/hpack
--
-- hash: c82d45f7d53e0e4b5e6b1efd72b97d7d54433e71dd7cb846abcf37807b183ff3
-- hash: cb97234e42a0696981bd86c74f9a64d2fa737b556dcddec6373e905d67968bf1
name: twenty-one
version: 0.1.0.0
......@@ -34,6 +34,7 @@ library
src
build-depends:
base >=4.7 && <5
, random >=1.1
default-language: Haskell2010
executable twenty-one-exe
......@@ -45,6 +46,7 @@ executable twenty-one-exe
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, random >=1.1
, twenty-one
default-language: Haskell2010
......@@ -58,5 +60,6 @@ test-suite twenty-one-test
ghc-options: -threaded -rtsopts -with-rtsopts=-N
build-depends:
base >=4.7 && <5
, random >=1.1
, twenty-one
default-language: Haskell2010
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please to comment