From 33122e06441b2422eaac4affee09644df8db6dbb Mon Sep 17 00:00:00 2001 From: Ryan Scott Date: Sun, 26 Jun 2022 11:15:23 -0400 Subject: [PATCH] Simplify the Eq/Ord instances for FT While slightly more verbose, the new instance contexts avoid the need for overlapping instances or `FlexibleContexts`. --- CHANGELOG.markdown | 5 +++++ src/Control/Monad/Trans/Free/Church.hs | 15 ++++++++++++--- 2 files changed, 17 insertions(+), 3 deletions(-) diff --git a/CHANGELOG.markdown b/CHANGELOG.markdown index 704d870..4de072b 100644 --- a/CHANGELOG.markdown +++ b/CHANGELOG.markdown @@ -1,3 +1,8 @@ +next [????.??.??] +----------------- +* Simplify the `Eq` and `Ord` instances for `FT` to avoid the use of + overlapping instances. + 5.1.8 [2022.05.07] ------------------ * Generalize the `Monad` constraint in the type signatures for diff --git a/src/Control/Monad/Trans/Free/Church.hs b/src/Control/Monad/Trans/Free/Church.hs index 1961c4c..df4ea6a 100644 --- a/src/Control/Monad/Trans/Free/Church.hs +++ b/src/Control/Monad/Trans/Free/Church.hs @@ -1,5 +1,4 @@ {-# LANGUAGE CPP #-} -{-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE RankNTypes #-} @@ -97,10 +96,20 @@ instance ( Functor f, Monad m, Ord1 f, Ord1 m compare1 x y = compare1 (fromFT x) (fromFT y) #endif -instance (Eq1 (FT f m), Eq a) => Eq (FT f m a) where +instance ( Functor f, Monad m, Eq1 f, Eq1 m +# if !(MIN_VERSION_base(4,8,0)) + , Functor m +# endif + , Eq a + ) => Eq (FT f m a) where (==) = eq1 -instance (Ord1 (FT f m), Ord a) => Ord (FT f m a) where +instance ( Functor f, Monad m, Ord1 f, Ord1 m +# if !(MIN_VERSION_base(4,8,0)) + , Functor m +# endif + , Ord a + ) => Ord (FT f m a) where compare = compare1 instance Functor (FT f m) where