#14643 closed bug (fixed)
Partial type signatures in class constraints behave unexpectedly
Reported by: | mnislaih | Owned by: | |
---|---|---|---|
Priority: | normal | Milestone: | 8.4.1 |
Component: | Compiler | Version: | 8.2.2 |
Keywords: | PartialTypeSignatures | Cc: | |
Operating System: | Unknown/Multiple | Architecture: | Unknown/Multiple |
Type of failure: | None/Unknown | Test Case: | partial-sigs/should_compile/T14643, T14643a |
Blocked By: | Blocking: | ||
Related Tickets: | Differential Rev(s): | ||
Wiki Page: |
Description
Minimal example:
{-# LANGUAGE PartialTypeSignatures #-} {-# LANGUAGE TemplateHaskell #-} module Minimal where id [d| f :: (Monad m, _) => [m a] -> m [a] f' :: (Monad m, _) => [m a] -> m [a] f = f' f' [] = return [] f' (x:xx) = f xx |]
[1 of 1] Compiling Minimal ( /Users/pepe/Dropbox/code/debug-hoed/test/minimal.hs, interpreted ) /Users/pepe/Dropbox/code/debug-hoed/test/minimal.hs:5:1: warning: [-Wpartial-type-signatures] • Found type wildcard ‘_’ standing for ‘()’ • In the type signature: f :: (Monad m_a7NN, _) => [m_a7NN a_a7NO] -> m_a7NN [a_a7NO] | 5 | id [d| | ^^^^^^... /Users/pepe/Dropbox/code/debug-hoed/test/minimal.hs:5:1: warning: [-Wpartial-type-signatures] • Found type wildcard ‘_’ standing for ‘()’ • In the type signature: f' :: (Monad m_a7NL, _) => [m_a7NL a_a7NM] -> m_a7NL [a_a7NM] | 5 | id [d| | ^^^^^^... Ok, one module loaded. :browse f :: (Monad m, Monad m) => [m a] -> m [a] f' :: (Monad m, Monad m) => [m a] -> m [a]
Notice the duplicate Monad m constraint.
Things get even more weird if the type signatures are declared together:
id [d| f, f' :: (Monad m, _) => [m a] -> m [a] f = f' f' [] = return [] f' (x:xx) = f xx |]
[1 of 1] Compiling Minimal ( /Users/pepe/Dropbox/code/debug-hoed/test/minimal.hs, interpreted ) /Users/pepe/Dropbox/code/debug-hoed/test/minimal.hs:5:1: warning: [-Wpartial-type-signatures] • Found type wildcard ‘_’ standing for ‘()’ • In the type signature: f :: (Monad m_a88E, _) => [m_a88E a_a88F] -> m_a88E [a_a88F] | 5 | id [d| | ^^^^^^... /Users/pepe/Dropbox/code/debug-hoed/test/minimal.hs:5:1: warning: [-Wpartial-type-signatures] • Found type wildcard ‘_’ standing for ‘()’ • In the type signature: f' :: (Monad m_a88E, _) => [m_a88E a_a88F] -> m_a88E [a_a88F] | 5 | id [d| | ^^^^^^... Ok, one module loaded. :browse f :: (Monad ghc-prim-0.5.1.1:GHC.Types.Any, Monad m) => [ghc-prim-0.5.1.1:GHC.Types.Any ghc-prim-0.5.1.1:GHC.Types.Any] -> ghc-prim-0.5.1.1:GHC.Types.Any [ghc-prim-0.5.1.1:GHC.Types.Any] f' :: (Monad ghc-prim-0.5.1.1:GHC.Types.Any, Monad m) => [m a] -> m [a]
Change History (9)
comment:1 Changed 13 months ago by
comment:2 Changed 13 months ago by
Summary: | Partial type signatures in spliced TH declarations behave unexpectedly → Partial type signatures interact unexpectedly with :browse |
---|
Note that this has nothing to do with Template Haskell. You can also trigger the issue with this (slightly more) minimal file:
{-# LANGUAGE PartialTypeSignatures #-} {-# LANGUAGE TemplateHaskell #-} module Bug where f :: (Monad m, _) => [m a] -> m [a] f' :: (Monad m, _) => [m a] -> m [a] f = f' f' [] = return [] f' (x:xx) = f xx g, g' :: (Monad m, _) => [m a] -> m [a] g = g' g' [] = return [] g' (x:xx) = g xx
$ ghci Bug.hs -Wno-partial-type-signatures GHCi, version 8.2.2: http://www.haskell.org/ghc/ :? for help Loaded GHCi configuration from /home/rgscott/.ghci [1 of 1] Compiling Bug ( Bug.hs, interpreted ) Ok, one module loaded. λ> :browse f :: (Monad m, Monad m) => [m a] -> m [a] f' :: (Monad m, Monad m) => [m a] -> m [a] g :: (Monad GHC.Types.Any, Monad m) => [GHC.Types.Any GHC.Types.Any] -> GHC.Types.Any [GHC.Types.Any] g' :: (Monad GHC.Types.Any, Monad m) => [m a] -> m [a]
The same behavior also happens with :type v
(but not :type
, since that performs deep instantiation of the types):
λ> :type +v f f :: (Monad m, Monad m) => [m a] -> m [a] λ> :type +v f' f' :: (Monad m, Monad m) => [m a] -> m [a] λ> :type +v g g :: (Monad GHC.Types.Any, Monad m) => [GHC.Types.Any GHC.Types.Any] -> GHC.Types.Any [GHC.Types.Any] λ> :type +v g' g' :: (Monad GHC.Types.Any, Monad m) => [m a] -> m [a]
comment:3 Changed 13 months ago by
Summary: | Partial type signatures interact unexpectedly with :browse → Partial type signatures in class constraints behave unexpectedly |
---|
Hi Ryan, thanks for the even smaller example! For some reason I didn't think of removing the TH splice. But just to clarify, this issue is not restricted to :browse
. The type signatures with Any
in them cannot be instantiated, or at least I haven't figured out how.
Found an even smaller example:
af, ag :: (Num a,_) => a -> a af = ag ag x = af(x-1)
The Num constraint is duplicated. Suggests the bug is related to tyvar identity
comment:5 Changed 13 months ago by
Status: | new → merge |
---|---|
Test Case: | → partial-sigs/should_compile/T14643, T14643a |
Thanks for the report. It was trickier than I thought, and showed up not one but two separate bugs.
We could merge this... it's an outright bug.
comment:8 Changed 12 months ago by
Milestone: | → 8.4.1 |
---|---|
Resolution: | → fixed |
Status: | merge → closed |
comment:9 Changed 10 months ago by
Keywords: | PartialTypeSignatures added |
---|
It looks the same under ghc 8.4 alpha: