O'Reilly logo

Functional Programming: A PragPub Anthology by Michael Swaine

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Writing an Equivalence Property

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 ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required