catbird icon indicating copy to clipboard operation
catbird copied to clipboard

Typeclass instances for Reader.

Open dangerousben opened this issue 5 years ago • 4 comments

  • Alternative
  • Defer
  • Monad
  • Monoid
  • Eq

dangerousben avatar Jul 31 '20 11:07 dangerousben

There seems to be an infinite recursion for Reader somewhere. Is this reproducible locally or only on CI (I haven't checked yet)?

felixbr avatar Aug 24 '20 07:08 felixbr

There seems to be an infinite recursion for Reader somewhere. Is this reproducible locally or only on CI (I haven't checked yet)?

It's reproducible (although somehow it didn't show up before I submitted the PR). IIRC the problem is that it's impossible to implement a valid Eq instance for Reader because comparing streams requires reading and thus mutating them.

I think the other typeclass instances are (at least from a practical point of view) valid, but the laws can't be tested without a working Eq.

dangerousben avatar Aug 24 '20 12:08 dangerousben

the problem is that it's impossible to implement a valid Eq instance for Reader

It might of course be possible to implement an invalid one that works well enough for the tests, but I haven't figured out how so far.

dangerousben avatar Aug 24 '20 12:08 dangerousben

the problem is that it's impossible to implement a valid Eq instance for Reader

It might of course be possible to implement an invalid one that works well enough for the tests, but I haven't figured out how so far.

For testing you could maybe drain the streams into local variables, compare them and reset the streams with the elements you drained. That is, of course, not a good idea in production, but maybe it's enough in the tests (with documentation why we have to do this).

edit: Some streaming implementation also allow copying/broadcasting a stream without mutating the "original" instance. I don't know if the Twitter ones have this, though.

felixbr avatar Aug 24 '20 13:08 felixbr