Skip to content

Hashable instance? #158

Description

@adamConnerSax

Would it be possible to add a Hashable instance for Rec ElField rs (with reasonable constraints on the rs)? I've added that here and there but that creates an orphan and I'm not sure I'm doing it right...

What I've got now (I've only ever used the "else" branch but that crashes ghc 9.2.2, hence the other version..which might be better?)

#if MIN_VERSION_base(4,16,0)
import GHC.Generics (Generic, Rep)
import Data.Hashable.Generic as Hash
#endif

-- | This is only here so we can use hash maps for the grouping step.  This should properly be in Frames itself.
#if MIN_VERSION_base(4,16,0)
instance (Generic (V.Rec V.ElField rs), Eq (V.Rec V.ElField rs), Hash.GHashable Hash.Zero (Rep (V.Rec V.ElField rs))) => Hash.Hashable (V.Rec V.ElField rs) where
  hashWithSalt = Hash.genericHashWithSalt
  {-# INLINEABLE hashWithSalt #-}
#else
instance Hash.Hashable (F.Record '[]) where
  hash = const 0
  {-# INLINABLE hash #-}
  hashWithSalt s = const s -- TODO: this seems BAD! Or not?
  {-# INLINABLE hashWithSalt #-}

instance (V.KnownField t, Hash.Hashable (V.Snd t), Hash.Hashable (F.Record rs), rs F.⊆ (t ': rs)) => Hash.Hashable (F.Record (t ': rs)) where
  hashWithSalt s r = s `Hash.hashWithSalt` (F.rgetField @t r) `Hash.hashWithSalt` (F.rcast @rs r)
  {-# INLINABLE hashWithSalt #-}
#endif

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions