From be020754619080b02ec0f9fb4cea0279bbf8f5a9 Mon Sep 17 00:00:00 2001 From: Ivan Gromakovskii Date: Tue, 16 Nov 2021 11:42:48 +0300 Subject: [PATCH] Support hashable-1.4 without warnings Problem: in hashable-1.4 `Eq` is a superclass of `Hashable`, it causes warnings in some code. Solution: use CPP to check `hashable` version and replace `(Eq a, Hashable a)` constraint with just `Hashable a` for new version. --- src/Universum/Nub.hs | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/src/Universum/Nub.hs b/src/Universum/Nub.hs index 813ae10f..4483550d 100644 --- a/src/Universum/Nub.hs +++ b/src/Universum/Nub.hs @@ -1,4 +1,5 @@ {-# LANGUAGE Safe #-} +{-# LANGUAGE CPP #-} {-| Functions to remove duplicates from a list. @@ -30,7 +31,9 @@ module Universum.Nub , unstableNub ) where +#if !MIN_VERSION_hashable(1,4,0) import Data.Eq (Eq) +#endif import Data.Hashable (Hashable) import Data.HashSet as HashSet import Data.Ord (Ord) @@ -55,7 +58,11 @@ ordNub = go Set.empty -- -- >>> hashNub [3, 3, 3, 2, 2, -1, 1] -- [3,2,-1,1] +#if MIN_VERSION_hashable(1,4,0) +hashNub :: (Hashable a) => [a] -> [a] +#else hashNub :: (Eq a, Hashable a) => [a] -> [a] +#endif hashNub = go HashSet.empty where go _ [] = [] @@ -75,5 +82,9 @@ sortNub = Set.toList . Set.fromList -- -- >>> unstableNub [3, 3, 3, 2, 2, -1, 1] -- [1,2,3,-1] +#if MIN_VERSION_hashable(1,4,0) +unstableNub :: (Hashable a) => [a] -> [a] +#else unstableNub :: (Eq a, Hashable a) => [a] -> [a] +#endif unstableNub = HashSet.toList . HashSet.fromList