July 2017
Intermediate to advanced
284 pages
6h 45m
English
Now that we have the basics out of the way, let’s begin to write a property on our code. Let’s try an equivalence property.
| | quickCheck (\s -> (caesar 2 s) == (native_caesar 2 s)) |
If we try running this, we will quickly encounter a type error.
| | *Main> quickCheck (\s -> (caesar 2 s) == (native_caesar 2 s)) |
| | |
| | <interactive>:2:36: |
| | Couldn't match type 'IO String' with '[Char]' |
| | Expected type: String |
| | Actual type: IO String |
| | In the second argument of '(==)', namely '(native_caesar 2 s)' |
| | In the expression: (caesar 2 s) == (native_caesar 2 s) |
This error comes from a discrepancy in the return types of our Caesar functions. The caesar function returns String, while the native_caesar function returns IO String ...
Read now
Unlock full access