[GHC] #8767: Add rules involving `coerce` to the libraries

GHC ghc-devs at haskell.org
Thu Sep 11 19:49:33 UTC 2014


#8767: Add rules involving `coerce` to the libraries
-------------------------------------+-------------------------------------
              Reporter:  nomeata     |            Owner:
                  Type:  task        |           Status:  new
              Priority:  normal      |        Milestone:  7.10.1
             Component:              |          Version:  7.9
  libraries/base                     |         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 dmcclean):

 I knew about the representational parameter part, that's why I thought
 maybe it was possible to only generate the instance if `f` has a
 representational parameter. i.e. it's not one once-and-for-all instance
 for all functors, instead it's "magically" (as the current coercible
 instances are) generated once at each functor type with the branching
 between `fmap coerce` and `coerce` happening after considering the
 concrete type of `f`.

 The bit about the lawfulness I had missed.

 I don't understand how it results in `Coercible (f a) (f b)` with no
 context, even if it is once-and-for-all and not the magical akin-to-an-
 axiom-schema way, but I'm sure you're correct.

 It seems like the unlawful functor desideratum is very difficult to handle
 because we don't have a way to have a qualified type that is qualified by
 whether or not the `Functor` is lawful.

 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'?)

 1) If the role is representational and there's no unlawful pragma, you
 generate `coerce`.
 2) If there's no unlawful pragma, but the role is something other than
 representational you generate `fmap coerce`.
 3) If there's an unlawful pragma, you generate `error "Attempt to coerce
 through unlawful functor Foo declared at line ..."`, on the grounds that
 `error` is not pretty, but neither is unlawfulness.

--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/8767#comment:21>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler


More information about the ghc-tickets mailing list