Ticket #12 (new task)

Opened 3 years ago

Simplify Eq and Ord instances

Reported by: rl Owned by:
Priority: trivial Milestone:
Version: Keywords:
Cc:

Description

We can simplify them when we drop support for GHC 6.12.

This is what they should look like:

instance (..., Eq a) => Eq (Vector a) where
  {-# INLINE (==) #-}
  (==) = Data.Vector.Generic.eq

instance (..., Ord a) => Ord (Vector a) where
  {-# INLINE compare #-}
  compare = Data.Vector.Generic.cmp

This works fine with 6.13 but result in atrocious code with 6.12 which essentially ignores the INLINE pragma. The workaround is this:

instance (..., Eq a) => Eq (Vector a) where
  {-# INLINE (==) #-}
  xs == ys = Stream.eq (G.stream xs) (G.stream ys)

  {-# INLINE (/=) #-}
  xs /= ys = not (Stream.eq (G.stream xs) (G.stream ys))

instance (..., Ord a) => Ord (Vector a) where
  {-# INLINE compare #-}
  compare xs ys = Stream.cmp (G.stream xs) (G.stream ys)

  {-# INLINE (<) #-}
  xs < ys = Stream.cmp (G.stream xs) (G.stream ys) == LT

  {-# INLINE (<=) #-}
  xs <= ys = Stream.cmp (G.stream xs) (G.stream ys) /= GT

  {-# INLINE (>) #-}
  xs > ys = Stream.cmp (G.stream xs) (G.stream ys) == GT

  {-# INLINE (>=) #-}
  xs >= ys = Stream.cmp (G.stream xs) (G.stream ys) /= LT

Ugly, but it works. This also requires the package (but not necessarily the clients!) to be compiled with -fno-method-sharing.

Note: See TracTickets for help on using tickets.