[GHC] #11385: Unify named wildcards in different type applications

GHC ghc-devs at haskell.org
Thu Aug 4 04:19:21 UTC 2016


#11385: Unify named wildcards in different type applications
-------------------------------------+-------------------------------------
        Reporter:  Iceland_jack      |                Owner:
            Type:  feature request   |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler (Type    |              Version:  8.1
  checker)                           |             Keywords:
      Resolution:                    |  NamedWildCards TypeApplications
Operating System:  Unknown/Multiple  |         Architecture:
                                     |  Unknown/Multiple
 Type of failure:  None/Unknown      |            Test Case:
      Blocked By:                    |             Blocking:
 Related Tickets:                    |  Differential Rev(s):
       Wiki Page:                    |
-------------------------------------+-------------------------------------

Comment (by Iceland_jack):

 Trying to wrap the [https://hackage.haskell.org/package/reflection
 reflection] API without `Proxy`, is there a way to implement this without
 visible type abstraction? This is `reflect`

 {{{#!hs
 reflect_ :: forall (s :: *) a. Reifies s a => a
 reflect_ = reflect @s Proxy

 reify_ :: a -> (forall (s :: *). Reifies s a => r) -> r
 reify_ a f = reify a (\(Proxy :: Proxy s) -> f @s)
 }}}

 Would this allow

 {{{#!hs
 reify 10 $ \p -> reflect p + reflect p
 }}}

 to be written as `↓`?

 {{{#!hs
 reify_ 10 $ \ @p -> reflect_ @p + reflect_ @p
 }}}

 ----

 Minimal `reflection` API:

 {{{#!hs
 {-# Language RankNTypes, TypeApplications, KindSignatures,
 MultiParamTypeClasses, FunctionalDependencies, ScopedTypeVariables,
 AllowAmbiguousTypes #-}

 import Unsafe.Coerce

 data Proxy k = Proxy

 class Reifies s a | s -> a where
   reflect :: proxy s -> a

 newtype Magic a r = Magic (forall (s :: *). Reifies s a => Proxy s -> r)

 reify :: forall a r. a -> (forall (s :: *). Reifies s a => Proxy s -> r)
 -> r
 reify a k = unsafeCoerce (Magic k :: Magic a r) (const a) Proxy
 {-# INLINE reify #-}
 }}}

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


More information about the ghc-tickets mailing list