[GHC] #11977: ghc doesn't agree with its own inferred pattern type

GHC ghc-devs at haskell.org
Wed May 18 07:30:54 UTC 2016


#11977: ghc doesn't agree with its own inferred pattern type
-------------------------------------+-------------------------------------
        Reporter:  Iceland_jack      |                Owner:
            Type:  bug               |               Status:  new
        Priority:  normal            |            Milestone:
       Component:  Compiler          |              Version:  8.1
      Resolution:                    |             Keywords:
                                     |  PatternSynonyms
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):

 Noticed while looking at Carter's
 [https://gist.github.com/cartazio/60eac732e7ac162916eaf828c9b1483c
 copatterns] and saw that the following compiles:

 {{{#!hs
 type Stream a = forall res . StreamTag a res -> res

 data StreamTag a res where
    HeadTag :: StreamTag a a
    -- TailTag :: StreamTag a (Stream a)

 pattern Head' :: res -> Stream res
 pattern Head' x <- (($ HeadTag) -> x)
 }}}

 but it is my understanding that `Stream` must be a newtype/data
 (generative) to be able to define `TailTag`:

 {{{#!hs
 newtype Stream a = Stream (forall res. StreamTag a res -> res)

 data StreamTag a res where
    HeadTag :: StreamTag a a
    TailTag :: StreamTag a (Stream a)

 pattern Head :: a -> Stream a
 pattern Head x <- ((\(Stream str) -> str HeadTag) -> x)

 pattern Tail :: Stream a -> Stream a
 pattern Tail xs <- ((\(Stream str) -> str TailTag) -> xs)

 pattern Cons :: a -> Stream a -> Stream a
 pattern Cons x xs <- ((\(Stream str) -> (str HeadTag, str TailTag)) -> (x,
 xs))

 headStream :: Stream a -> a
 headStream (Head x) = x

 tailStream :: Stream a -> Stream a
 tailStream (Tail xs) = xs

 rawRawZipWith :: (a -> b -> c) -> (Stream a -> Stream b -> Stream c )
 rawRawZipWith f sta stb = Stream $ \str -> do
   let Head x  = sta
       Head y  = stb
       Tail xs = sta
       Tail ys = stb

   case str of
     HeadTag -> f x y
     TailTag -> rawRawZipWith f xs ys

 rawRawZipWith' :: (a -> b -> c) -> (Stream a -> Stream b -> Stream c)
 rawRawZipWith' f (Cons x xs) (Cons y ys) = Stream $ \case
   HeadTag -> f x y
   TailTag -> rawRawZipWith f xs ys

 }}}

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


More information about the ghc-tickets mailing list