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
Closed

Add rwhnf helper for NF=WHNF instances #3

hvr opened this issue Nov 15, 2014 · 2 comments

Comments

@hvr
Copy link
Member

hvr 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 !_ = ()
@RyanGlScott
Copy link
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

@bgamari
Copy link
Contributor

bgamari 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
Development

No branches or pull requests

3 participants