
#8767: Add rules involving `coerce` to the libraries -------------------------------------+------------------------------------- Reporter: nomeata | Owner: ekmett Type: task | Status: new Priority: normal | Milestone: 7.10.1 Component: Core | Version: 7.9 Libraries | Keywords: Resolution: | Architecture: Unknown/Multiple Operating System: | Difficulty: Unknown Unknown/Multiple | Blocked By: 8718 Type of failure: | Related Tickets: #2110 None/Unknown | Test Case: | tests/simplCore/should_run/T2110.hs| Blocking: | Differential Revisions: | -------------------------------------+------------------------------------- Comment (by dfeuer): Replying to [comment:21 dmcclean]:
One possible thing would be to have an {-# UNLAWFUL #-} pragma, and when you are magically generating instances you branch three ways instead of 2. (Possibly such a pragma could allow more aggressive optimizations in other cases too, with an opt out for 'criminals'?)
I think it would make more sense to track `Functor` instances believed to be (sufficiently) lawful. A functor could be labeled `{-# LAWFUL #-}` in either `Unsafe` or `Trustworthy` modules, and any ''derived'' `Functor` instance without a `Functor` context could be treated as lawful as well. A functor labeled as `{-# LAWFUL #-}` could of course be lawful only up to some isomorphism; the pragma would declare that the instance won't break in any important way if the compiler relies on the functor laws. A similar mechanism could presumably be applied to other classes as well. Interaction with extreme polymorphism: to really take advantage, you'd presumably need to be able to express lawfulness in a context. So you'd need to be able to write something like {{{#!hs g :: ({-# LAWFUL #-} Functor f) => ... }}}} -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/8767#comment:25 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler