matrix icon indicating copy to clipboard operation
matrix copied to clipboard

Monoid applicative tests

Open octopuscabbage opened this issue 9 years ago • 11 comments
trafficstars

This PR is downstream from #21 and #27

octopuscabbage avatar Jan 27 '16 02:01 octopuscabbage

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 avatar Jan 27 '16 02:01 octopuscabbage

We're good now

octopuscabbage avatar Jan 27 '16 03:01 octopuscabbage

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:

Daniel-Diaz avatar Jan 27 '16 03:01 Daniel-Diaz

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

octopuscabbage avatar Jan 27 '16 03:01 octopuscabbage

Check CoArbitrary.

Daniel-Diaz avatar Jan 27 '16 03:01 Daniel-Diaz

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

Daniel-Diaz avatar Jan 27 '16 03:01 Daniel-Diaz

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

octopuscabbage avatar Jan 27 '16 03:01 octopuscabbage

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

Daniel-Diaz avatar Jan 27 '16 03:01 Daniel-Diaz

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

octopuscabbage avatar Jan 27 '16 04:01 octopuscabbage

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.

Daniel-Diaz avatar Jan 27 '16 04:01 Daniel-Diaz

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.

octopuscabbage avatar Jan 27 '16 04:01 octopuscabbage