Skip to content

error found hole: _ is not appropriate in the following case

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.

Trac metadata
Trac field Value
Version 8.0.2
Type FeatureRequest
TypeOfFailure OtherFailure
Priority normal
Resolution Unresolved
Component Compiler
Test case
Differential revisions
BlockedBy
Related
Blocking
CC
Operating system
Architecture
To upload designs, you'll need to enable LFS and have an admin enable hashed storage. More information