Skip to content

Commit

Permalink
Support hashable-1.4 without warnings
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
gromakovsky committed Nov 16, 2021
1 parent 37a2ce5 commit be02075
Showing 1 changed file with 11 additions and 0 deletions.
11 changes: 11 additions & 0 deletions src/Universum/Nub.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
{-# LANGUAGE Safe #-}
{-# LANGUAGE CPP #-}

{-| Functions to remove duplicates from a list.
Expand Down Expand Up @@ -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)
Expand All @@ -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 _ [] = []
Expand All @@ -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

0 comments on commit be02075

Please sign in to comment.