[GHC] #13557: error found hole: _ is not appropriate in the following case

GHC ghc-devs at haskell.org
Mon Apr 10 13:31:51 UTC 2017


#13557: error found hole: _ is not appropriate in the following case
-------------------------------------+-------------------------------------
           Reporter:  vanto          |             Owner:  (none)
               Type:  feature        |            Status:  new
  request                            |
           Priority:  normal         |         Milestone:
          Component:  Compiler       |           Version:  8.0.2
           Keywords:                 |  Operating System:  Unknown/Multiple
       Architecture:                 |   Type of failure:  Incorrect
  Unknown/Multiple                   |  error/warning at compile-time
          Test Case:                 |        Blocked By:
           Blocking:                 |   Related Tickets:
Differential Rev(s):                 |         Wiki Page:
-------------------------------------+-------------------------------------
 {{{
 f :: [Char]
 f =  [x | x <- ['a', 'b'],
  y <- (undefined:undefined:undefined:[]),
  z <- [1,2,3,4],
  r <- [True,False,True,False,True]]

 f' :: [Char]
 f' =  [x | x <- ['a', 'b'],
  y <- (undefined:undefined:undefined:[]),
  z <- [1,2,3,4],
  r <- [True, False, True, False, True],
  s <- [_, _, _, _, _, _]]

 main :: IO ()
 main = do
     print f
     print f'

 }}}
 When the code is compiled with the function {{{f}}} the result is the
 following:\\

 {{{
 "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaabbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbbb"
 }}}
 If we add in {{{f}}} the code {{{s <- [_, _, _, _, _, _]}}} to become the
 function {{{f'}}} and then compile the program, the following error is
 displayed.\\


 {{{
 test11.hs:5:131: error:
     * Found hole: _ :: t0
       Where: `t0' is an ambiguous type variable
     * In the expression: _
       In the expression: [_, _, _, _, ....]
       In a stmt of a list comprehension: s <- [_, _, _, _, ....]
     * Relevant bindings include
         r :: Bool (bound at test11.hs:5:86)
         z :: Integer (bound at test11.hs:5:70)
         y :: t1 (bound at test11.hs:5:29)
         x :: Char (bound at test11.hs:5:12)
         f' :: [Char] (bound at test11.hs:5:1)

 test11.hs:5:134: error:
     * Found hole: _ :: t0
       Where: `t0' is an ambiguous type variable
     * In the expression: _
       In the expression: [_, _, _, _, ....]
       In a stmt of a list comprehension: s <- [_, _, _, _, ....]
     * Relevant bindings include
         r :: Bool (bound at test11.hs:5:86)
         z :: Integer (bound at test11.hs:5:70)
         y :: t1 (bound at test11.hs:5:29)
         x :: Char (bound at test11.hs:5:12)
         f' :: [Char] (bound at test11.hs:5:1)

 test11.hs:5:137: error:
     * Found hole: _ :: t0
       Where: `t0' is an ambiguous type variable
     * In the expression: _
       In the expression: [_, _, _, _, ....]
       In a stmt of a list comprehension: s <- [_, _, _, _, ....]
     * Relevant bindings include
         r :: Bool (bound at test11.hs:5:86)
         z :: Integer (bound at test11.hs:5:70)
         y :: t1 (bound at test11.hs:5:29)
         x :: Char (bound at test11.hs:5:12)
         f' :: [Char] (bound at test11.hs:5:1)

 test11.hs:5:140: error:
     * Found hole: _ :: t0
       Where: `t0' is an ambiguous type variable
     * In the expression: _
       In the expression: [_, _, _, _, ....]
       In a stmt of a list comprehension: s <- [_, _, _, _, ....]
     * Relevant bindings include
         r :: Bool (bound at test11.hs:5:86)
         z :: Integer (bound at test11.hs:5:70)
         y :: t1 (bound at test11.hs:5:29)
         x :: Char (bound at test11.hs:5:12)
         f' :: [Char] (bound at test11.hs:5:1)

 test11.hs:5:143: error:
     * Found hole: _ :: t0
       Where: `t0' is an ambiguous type variable
     * In the expression: _
       In the expression: [_, _, _, _, ....]
       In a stmt of a list comprehension: s <- [_, _, _, _, ....]
     * Relevant bindings include
         r :: Bool (bound at test11.hs:5:86)
         z :: Integer (bound at test11.hs:5:70)
         y :: t1 (bound at test11.hs:5:29)
         x :: Char (bound at test11.hs:5:12)
         f' :: [Char] (bound at test11.hs:5:1)

 test11.hs:5:146: error:
     * Found hole: _ :: t0
       Where: `t0' is an ambiguous type variable
     * In the expression: _
       In the expression: [_, _, _, _, ....]
       In a stmt of a list comprehension: s <- [_, _, _, _, ....]
     * Relevant bindings include
         r :: Bool (bound at test11.hs:5:86)
         z :: Integer (bound at test11.hs:5:70)
         y :: t1 (bound at test11.hs:5:29)
         x :: Char (bound at test11.hs:5:12)
         f' :: [Char] (bound at test11.hs:5:1)


 }}}
 I think that here the wildcard pattern _ is justified and does not have to
 give this error and must be used as undefined.\\
 So this error makes no sense here.\\
 I propose to make a correction in this case.

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


More information about the ghc-tickets mailing list