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.
https://repl.it/languages/haskell
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)
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"]
add by your own functions.
trials variable to execute your code against
various cases.
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:
add
and main, and then sets trails to a list of
test runs. The show function converts values into strings
(so the result can be added to a string). There are other ways to run
multiple test cases, but this one uses no new constructs.
main with no
parameters to run the code. The ::IO () code (above) just means
that main is a function that does output. Repl.it will
execute main to do the work.