Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add `rwhnf` helper for NF=WHNF instances #3

Closed
hvr opened this issue Nov 15, 2014 · 2 comments

Comments

@hvr
Copy link
Member

commented Nov 15, 2014

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 !_ = ()

@hvr hvr added the enhancement label Nov 17, 2014

@RyanGlScott

This comment has been minimized.

Copy link
Member

commented Feb 18, 2016

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

@bgamari

This comment has been minimized.

Copy link
Contributor

commented Feb 18, 2016

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
Projects
None yet
3 participants
You can’t perform that action at this time.