Running Haskell online (at Repl.it)

This is an alterantive to running GHCI

This avoids having to install GHCI, but it's also slower (for very large problems!) 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.
You might also find it useful to use tuples for tests that return different types:
        f x = x * x
        main = putStrLn(show (f 3, f (-1), f 1.2))

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

GHCI at Repl.com

Notes