
#14547: Wrong warning by -Wincomplete-patterns -------------------------------------+------------------------------------- Reporter: YoshikuniJujo | Owner: (none) Type: bug | Status: patch Priority: low | Milestone: Component: Compiler | Version: 8.2.1 Resolution: | Keywords: incomplete- | patterns OverloadedLists, | PatternMatchWarnings TypeFamilies Operating System: Linux | Architecture: x86 Type of failure: Incorrect | Test Case: error/warning at compile-time | deSugar/should_compile/T14547 Blocked By: | Blocking: Related Tickets: | Differential Rev(s): Phab:D4624 Wiki Page: | -------------------------------------+------------------------------------- Comment (by sighingnow): Replying to [comment:7 simonpj]: Thanks for your explanation and analysis, Simon. I agree to add a note to explain this condition. Now I have some other thought with the `ListPat` case of `translatePat`.
You are checking that the function actually has type [t1] -> [t2], where normalise t1 = normalise t2.
I think in fact we don't need to do the check. For `ListPat x lpats elem_ty (Just (pat_ty, _to_list))`, we know the `_to_list` have type: {{{ toList :: l -> [Item l] }}} If we know the `pat_ty` (the `l` in toList's signature) is `[a]` (the List type), then we can conclude that `Item l = a`, in other words, `norm_elem_ty = norm_e_ty`. Because in `instance IsList [a]`, we have `type (Item [a]) = a`. Although we can give an instance IsList [Int] (more specific than the default IsList [a]), we can't overwrite the type family instance. The original comment says:
{{{ -- We have to ensure that the element types are exactly the same. -- Otherwise, one may give an instance IsList [Int] (more specific than -- the default IsList [a]) with a different implementation for `toList' }}}
However we can't achieve this goal without check the type of `_to_list`. In practice, we almost never define more specific IsList instance like `instance IsList [Int]`, we don't need to concern that case. So we can simplify the code as {{{#!hs ListPat x lpats elem_ty (Just (pat_ty, _to_list)) | Just e_ty <- splitListTyConApp_maybe pat_ty -> translatePat fam_insts (ListPat x lpats e_ty Nothing) | otherwise -> mkCanFailPmPat pat_ty }}} Or should be check whether the type of `_to_list` is `[a] -> [a]` (the most general type) ? I don't think it's necessary for practical Haskell code. **I'm not sure if I understand this correctly.** Another silly question is that I still can't see why we need to concern about the view pattern for exhaustiveness checking of overloaded list. I think the `toList` and the `[a]` instance of `IsList` are different with ordinary view functions in view pattern. I will mention this in the note. -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14547#comment:9 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler