Remix.run Logo
roryc89 4 hours ago

In most FP languages it is simple to print to screen and get a random number.

Pure functions often exist in practice and are useful for preventing many bugs. Sure, they may not be suitable for some situations but they can prevent a lot of foot guns.

Here's a Haskell example with all of the above:

  import System.Random (randomRIO)

  main :: IO ()
  main = do
    num <- randomRIO (1, 100)
    print $ pureFunction num

  pureFunction :: Int -> Int
  pureFunction x = x * x + 2 * x + 1