Daniel-Diaz / matrix

A Haskell native implementation of matrices and their operations.
BSD 3-Clause "New" or "Revised" License
35 stars 31 forks source link

Monoid applicative tests #28

Open octopuscabbage opened 8 years ago

octopuscabbage commented 8 years ago

This PR is downstream from #21 and #27

octopuscabbage commented 8 years ago

I just realized I'm a dingus and couldn't get the applicative tests to run becuase I never gave the functions a type constraint.

octopuscabbage commented 8 years ago

We're good now

Daniel-Diaz commented 8 years ago

Those tests for applicative laws are not valid. They use 1x1 matrices, but the size must be arbitrary (within a reasonable range). Matrix is instance of Arbitrary, so it shouldn't be that hard.

Also... Branch conflicts? I just accepted your other patch, so this is weird. :octocat:

octopuscabbage commented 8 years ago

The problem I was having was generating Arbitrary matricies of functions. I suppose I could write a custom instance

Daniel-Diaz commented 8 years ago

Check CoArbitrary.

Daniel-Diaz commented 8 years ago

In particular, if a is instance of CoArbitrary, and b is instance of Arbitrary, then a -> b is instance of Arbitrary.

In other words: (CoArbitrary a, Arbitrary b) => Arbitrary (a -> b).

This gives you Arbitrary instance for Matrix (a -> b).

octopuscabbage commented 8 years ago

well that's a lot easier than what i was doing

Daniel-Diaz commented 8 years ago

Yeah, you don't have to do anything. Int is coarbitrary, so just use the matrices with the right type (like Matrix (Int ->Int)).

octopuscabbage commented 8 years ago

I'm getting a weird error where it's saying that (Int -> Int) isn't showable

Daniel-Diaz commented 8 years ago

True... The argument of the property function you are testing must be instance of Show(so that counterexamples show up in screen when found). At the moment, it's fine to just add dummy instance for functions. I can improve it later.

octopuscabbage commented 8 years ago

I went ahead and wrote a dummy instance of show for (Int->Int). This required turning on flexible instances in the testing source but it shouldn't be an issue since it's only test.

We might want to constrain down the functions to a finite type (Bool -> Bool) then we could write actual instances for show for that type.