Using GHCI to test Props

35 views
Skip to first unread message

Jimmy P

unread,
Sep 1, 2015, 6:50:56 PM9/1/15
to haskell-exercises
Hi everyone,

I did the NICTA course with Tony down in melbourne a few months ago, and while we didn't have property based testing set up Tony showed us a way to use the props in the REPL...

So if I had:
-- | Return the length of the list.
--
-- >>> length (1 :. 2 :. 3 :. Nil)
-- 3
--
-- prop> sum (map (const 1) x) == length x
length ::
  List a
  -> Int
length = undefined


I could do something like:
>> props x = sum (map (const 1) x) == length x
>> props (1:.2:.3:.4:.Nil)

true

But clearly I've forgotten how to do it properly because all I get is:
<interactive>:93:8: parse error on input ‘=’

Cheers,
Jim

Charles O'Farrell

unread,
Sep 1, 2015, 6:56:21 PM9/1/15
to Jimmy P, haskell-exercises
Hi Jimmy,

In GHCI you need to let-bind the functions you're creating:

>> let props x = sum (map (const 1) x) == length x

I hope that helps.
Charles

--
You received this message because you are subscribed to the Google Groups "haskell-exercises" group.
To unsubscribe from this group and stop receiving emails from it, send an email to haskell-exerci...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Jimmy P

unread,
Sep 1, 2015, 7:08:41 PM9/1/15
to Charles O'Farrell, haskell-exercises
Gah! That was it! Thank you Charles :)
Reply all
Reply to author
Forward
0 new messages