@EmmanuelLongeau/

FunWithFunctions

Haskell

No description

fork
loading
Files
  • main.hs

This Plugin Crashed!

Error: Error: must not create an existing file {"type":"CREATE_FILE","wid":"0.04380093334179924","path":"main.hs","file":{"path":"main.hs","content":{"asEncoding":{"base64":"dHlwZSBUZXN0UmVzdWx0ID0gKFN0cmluZywgQm9vbCkKCnNob3VsZCA6OiBTdHJpbmcgLT4gQm9vbCAtPiBUZXN0UmVzdWx0CnNob3VsZCBsYWJlbCByZXN1bHQgPSAobGFiZWwsIHJlc3VsdCkKCmZvcm1hdE9uZSA6OiBUZXN0UmVzdWx0IC0+IFN0cmluZwpmb3JtYXRPbmUgKGxhYmVsLCByZXN1bHQpID0gIiAgIiArKyBsYWJlbCArKyAiICIgKysgc2hvdyByZXN1bHQKCmZvcm1hdCA6OiBbVGVzdFJlc3VsdF0gLT4gW1N0cmluZ10KZm9ybWF0ID0gbWFwIGZvcm1hdE9uZSAKCmFkZExhYmVsIDo6IFN0cmluZyAtPiBbU3RyaW5nXSAtPiBbU3RyaW5nXQphZGRMYWJlbCBsYWJlbCByZXBvcnRzID0gbGFiZWwgOiByZXBvcnRzCgoofD4pIDo6IGEgLT4gKGEgLT4gYikgLT4gYgp4IHw+IGYgPSBmIHgKCmRlc2NyaWJlIDo6IFN0cmluZyAtPiBbVGVzdFJlc3VsdF0gLT4gU3RyaW5nCmRlc2NyaWJlIGxhYmVsIHJlc3VsdHMgPSAKICAgIHJlc3VsdHMgfD4gZm9ybWF0IHw+IGFkZExhYmVsIGxhYmVsIHw+IHVubGluZXMKCm1haW4gOjogSU8gKCkKbWFpbiA9IHB1dFN0ckxuICQgZGVzY3JpYmUgIkFkZGl0aW9uIiBbCiAgICAgICAgc2hvdWxkICIxICsgMSA9PSAyIiAkIDEgKyAxID09IDIsCiAgICAgICAgc2hvdWxkICIyICsgMiA9PSAzIiAkIDIgKyAyID09IDMKICAgIF0="},"asBuffer":null},"loaded":true}}
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
type TestResult = (String, Bool)

should :: String -> Bool -> TestResult
should label result = (label, result)

formatOne :: TestResult -> String
formatOne (label, result) = "  " ++ label ++ " " ++ show result

format :: [TestResult] -> [String]
format = map formatOne 

addLabel :: String -> [String] -> [String]
addLabel label reports = label : reports

(|>) :: a -> (a -> b) -> b
x |> f = f x

describe :: String -> [TestResult] -> String
describe label results = 
    results |> format |> addLabel label |> unlines

main :: IO ()
main = putStrLn $ describe "Addition" [
        should "1 + 1 == 2" $ 1 + 1 == 2,
        should "2 + 2 == 3" $ 2 + 2 == 3
    ]
GHCi, version 8.6.5