Visitar URL original
Add `rwhnf` helper for NF=WHNF instances · Issue #3 · haskell/deepseq · GitHub
Skip to content

Add rwhnf helper for NF=WHNF instances #3

Closed

Description

@hvr

Here's an idea for a helper I wanted to document:

-- | Reduce to weak head normal form
--
-- Useful for defining 'NFData' for types for which NF=WHNF holds.
--
-- > data T = C1 | C2 | C3
-- > instance NFData T where rnf = rwhnf
rwhnf :: a -> ()
rwhnf !_ = ()

Activity

  1. RyanGlScott commented on Feb 18, 2016

    @RyanGlScott
    Member

    As of GHC 8.0, it would be possible to enforce such a property via GHC generics! https://github.com/iu-parfunc/cnf-mutable-tests/blob/2b48584de0302553e9bf099d373bbe66b06b70c1/GenericExample.hs#L24-L79

  2. bgamari commented on Feb 18, 2016

    @bgamari
    Contributor

    Actually, you may even be able to automatically choose from between deep and shallow seq (although I don't quite know how to deal with the Rec0 case while avoiding potentially sending the typechecker into a loop): https://gist.github.com/bgamari/b67becc433026e80ba2b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions