[GHC] #11974: `default` declaration doesn't allow higher-kinded types
GHC
ghc-devs at haskell.org
Mon May 9 07:32:42 UTC 2016
#11974: `default` declaration doesn't allow higher-kinded types
-------------------------------------+-------------------------------------
Reporter: goldfire | Owner:
Type: bug | Status: patch
Priority: normal | Milestone:
Component: Compiler | Version: 8.1
Resolution: | Keywords:
Operating System: Unknown/Multiple | Architecture:
| Unknown/Multiple
Type of failure: None/Unknown | Test Case:
Blocked By: | Blocking:
Related Tickets: | Differential Rev(s): Phab:D2136
Wiki Page: |
-------------------------------------+-------------------------------------
Comment (by Iceland_jack):
Let's say you have
{{{#!hs
type Type₁ = Type
type Num₁ = Num
data Exp₁ (ty :: Type₁) where
N₁ :: Num₁ n => Exp₁ n
deriving instance Show (Exp₁ ty)
}}}
{{{
ghci> :set -fwarn-type-defaults
ghci> N₁
... warning: [-Wtype-defaults]
• Defaulting the following constraint to type ‘Integer’
Num n0 arising from a use of ‘it’
...
N₁
}}}
and you avoid writing `N₁ :: Exp₁ Integer` because of defaulting.
If however one indexes it with a promoted data type
{{{#!hs
data Type₂ = Integer₂ | Int32₂ | Bool₂
class Num₂ (a :: Type₂)
instance Num₂ 'Integer₂
instance Num₂ 'Int32₂
data Exp₂ (ty :: Type₂) where
N₂ :: Num₂ n => Exp₂ n
deriving instance Show (Exp₂ ty)
}}}
but showing it errors
{{{
ghci> N₂
<interactive>:3:1: error:
• Ambiguous type variable ‘n0’ arising from a use of ‘it’
prevents the constraint ‘(Num₂ n0)’ from being solved.
Probable fix: use a type annotation to specify what ‘n0’ should be.
These potential instances exist:
instance Num₂ 'Int32₂ -- Defined at /tmp/tyGL.hs:11:10
instance Num₂ 'Integer₂ -- Defined at /tmp/tyGL.hs:10:10
• In the first argument of ‘print’, namely ‘it’
In a stmt of an interactive GHCi command: print it
ghci>
}}}
I needed this and remembered this ticket. I want to write something like
{{{#!hs
default ('Integer₂)
-- Using https://prime.haskell.org/wiki/Defaulting#Proposal1-nametheclass
default Num₂ ('Integer₂)
}}}
Comment got to long, may split it
--
Ticket URL: <http://ghc.haskell.org/trac/ghc/ticket/11974#comment:4>
GHC <http://www.haskell.org/ghc/>
The Glasgow Haskell Compiler
More information about the ghc-tickets
mailing list