
#14380: Compile error for PatternSynonyms together with OverloadedLists -------------------------------------+------------------------------------- Reporter: lehins | Owner: (none) Type: bug | Status: new Priority: normal | Milestone: Component: Compiler | Version: 8.3 Keywords: | Operating System: Unknown/Multiple Architecture: | Type of failure: None/Unknown Unknown/Multiple | Test Case: | Blocked By: Blocking: | Related Tickets: Differential Rev(s): | Wiki Page: -------------------------------------+------------------------------------- {{{#!hs {-# LANGUAGE OverloadedLists #-} {-# LANGUAGE PatternSynonyms #-} data Foo = Foo [Int] pattern Bar :: Foo pattern Bar = Foo [] }}} This code results in a cryptic compilation error: {{{ $ ghc main.hs [1 of 1] Compiling Main ( main.hs, main.o ) main.hs:7:19: error: • Couldn't match expected type ‘[a0] -> [Int]’ with actual type ‘[GHC.Exts.Item Int]’ • This rebindable syntax expects a function with two arguments, but its type ‘Int -> [GHC.Exts.Item Int]’ has only one In the first argument of ‘Foo’, namely ‘[]’ In the expression: Foo [] | 7 | pattern Bar = Foo [] | ^^ }}} As soon as `OverloadedLists` is removed, this error goes away. In itself the problem isn't too critical, but very unexpected. I got above error with GHC 8.0 and 8.2, so decided to check it with current version as well: {{{ $ ghc --version The Glorious Glasgow Haskell Compilation System, version 8.3.20171020 }}} Looking a bit more into `PatternSynonyms` extension I was able to work around this by declaring an explicit bidirectional pattern, which, surprisingly, solved the problem: {{{#!hs pattern Bar :: Foo pattern Bar <- Foo [] where Bar = Foo [] }}} If fixing this issue is too much trouble than it is worth, than at least a mention about it in documentation will be helpful. Out of curiosity I also tried it with `String`, which did not trigger this error and compiled just fine: {{{#!hs {-# LANGUAGE OverloadedLists #-} {-# LANGUAGE OverloadedStrings #-} {-# LANGUAGE PatternSynonyms #-} data Foo = Foo [Char] pattern Bar :: Foo pattern Bar = Foo "" }}} PS. Even if this issue is closed, searching the internet for the error message will now at least return some info. :) -- Ticket URL: http://ghc.haskell.org/trac/ghc/ticket/14380 GHC http://www.haskell.org/ghc/ The Glasgow Haskell Compiler