An alterantive to running GHCI

Some students are having problems installing GHCI. A work-around is to use an online version. However, this is both slower and requires you to revise how you write the code a bit.

  1. Visit https://repl.it/languages/haskell
  2. Enter the following code in main.hs:
    module Main where
    
    add a b = if a == b then 2 * a else a + b
    
    trials = ["Test 1: add 8 and 5: " ++ (show (add 8 5)),
              "Test 2: add -3 and 4: " ++ (show (add (-3) 4)),
              "Test 3: add 9 and 9: " ++ (show (add 9 9))]
    
    main :: IO ()
    main = putStrLn (show trials)
    
  3. Click on the Run > button and confirm you get output like
            ["Test 1: add 8 and 5: 13","Test 2: add -3 and 4: 1","Test 3: add 9 and 9: 18"]
    
  4. Replace the definition of add by your own functions.
  5. Rewrite the trials variable to execute your code against various cases.
  6. Run your code and debug as necessary.

Just in case you're having problems, here's what I see:

GHCI at Repl.com