property testing, point-free style

Dear Cafe, The expression \x -> f x == g x is a testable property, as long as values for x can be randomly generated. For clarity I'd prefer a point-free style, e.g. f ≡ g Are there extensions to QuickCheck that let me write this? The QuickCheck package itself does not seem to contain such an operator. My current work-around is a newtype ExtensionalEquality a b that holds two functions of type (a -> b) and a Testable instance for it. But I've got a hunch that I re-invented some wheel here. (My ExtensionalEquality is isomorphic to Refl (a -> b) (a -> b) but Refl ist conceptually about type equality, not term equality.) Thanks Olaf

Maybe I'm missing something, but can't you just define:
(≡) f g = (f &&& g) >>^ (==)
(You could also define it as: (≡) f g x = f x == g x)
And use ≡ at will?
Why do you need an instance or a newtype?
Ivan
On Wed, 31 May 2023 at 04:25, Olaf Klinke
Dear Cafe,
The expression
\x -> f x == g x
is a testable property, as long as values for x can be randomly generated. For clarity I'd prefer a point-free style, e.g.
f ≡ g
Are there extensions to QuickCheck that let me write this? The QuickCheck package itself does not seem to contain such an operator. My current work-around is a newtype ExtensionalEquality a b that holds two functions of type (a -> b) and a Testable instance for it. But I've got a hunch that I re-invented some wheel here. (My ExtensionalEquality is isomorphic to Refl (a -> b) (a -> b) but Refl ist conceptually about type equality, not term equality.)
Thanks Olaf
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

On Wed, 2023-05-31 at 05:36 -0700, Ivan Perez wrote:
Maybe I'm missing something, but can't you just define:
(≡) f g = (f &&& g) >>^ (==)
(You could also define it as: (≡) f g x = f x == g x)
And use ≡ at will?
Why do you need an instance or a newtype?
Ivan
Hah, indeed. Stupid me. I was overthinking it and made the return type of (≡) a GADT with the Arbitrary constraint baked in, but that constraint is going to be checked at the call site anyways. Thanks!
On Wed, 31 May 2023 at 04:25, Olaf Klinke
wrote: Dear Cafe,
The expression
\x -> f x == g x
is a testable property, as long as values for x can be randomly generated. For clarity I'd prefer a point-free style, e.g.
f ≡ g
Are there extensions to QuickCheck that let me write this? The QuickCheck package itself does not seem to contain such an operator. My current work-around is a newtype ExtensionalEquality a b that holds two functions of type (a -> b) and a Testable instance for it. But I've got a hunch that I re-invented some wheel here. (My ExtensionalEquality is isomorphic to Refl (a -> b) (a -> b) but Refl ist conceptually about type equality, not term equality.)
Thanks Olaf
_______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.

Hi Olaf, You might like quickcheck-higherorder, "A QuickCheck extension for properties of higher-order values." https://hackage.haskell.org/package/quickcheck-higherorder One of the key bits is a class for testable equality, which may have an instance for (a -> b), unlike Eq: |class TestEq a where (=?) :: a -> a -> Property ||| The package has more bells and whistles to further streamline writing properties that quantify over functions. If you only ever compare unary first-order functions, you really only need the single instance TestEq (a -> b), which you can extract as a self-contained operator: (=?) :: (Coarbitrary a, Show a, Arbitrary b, Eq b, Show b) => (a -> b) -> (a -> b) -> Property (=?) f g = property $ \x -> f x === g x Regards, Li-yao || On 2023-05-31 12:25 PM, Olaf Klinke wrote: Dear Cafe, The expression \x -> f x == g x is a testable property, as long as values for x can be randomly generated. For clarity I'd prefer a point-free style, e.g. f ≡ g Are there extensions to QuickCheck that let me write this? The QuickCheck package itself does not seem to contain such an operator. My current work-around is a newtype ExtensionalEquality a b that holds two functions of type (a -> b) and a Testable instance for it. But I've got a hunch that I re-invented some wheel here. (My ExtensionalEquality is isomorphic to Refl (a -> b) (a -> b) but Refl ist conceptually about type equality, not term equality.) Thanks Olaf _______________________________________________ Haskell-Cafe mailing list To (un)subscribe, modify options or view archives go to: http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe Only members subscribed via the mailman list are allowed to post.
participants (3)
-
Ivan Perez
-
Li-yao Xia
-
Olaf Klinke