How do you get 100% code coverage with guards in Haskell?
- by dan_waterworth
I'm trying to get (and prove) 100% test coverage for some code I'm writing in Haskell using HPC. However if I write something like this:
fac n | n > 0 = n * (fac (n - 1))
| otherwise = 1
Then the second expression of the guard statement has always True tagged to it. What is the easiest way to overcome this in the general case?
edit:
Just to clarify. This code:
fac n = if n > 0 then n * (fac (n - 1))
else 1
Works fine with HPC, (running it gives 100% code coverage).
I'm basically suffering from this problem: http://hackage.haskell.org/trac/ghc/ticket/3175