[Haskell-cafe] What are the problems with instances for polymorphic types?
Ki Yung Ahn
kyagrd at gmail.com
Mon Jun 16 08:47:40 UTC 2014
The only value that inhabits (forall a. [a]), except bottom, is the
empty list []. You can actually experiment this with ghci.
shell-prompt$ ghci -XRankNTypes
GHCi, version 7.6.3: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Prelude> [] :: (forall a. [a])
[]
Prelude> [True] :: (forall a. [a])
<interactive>:7:2:
Couldn't match expected type `a1' with actual type `Bool'
`a1' is a rigid type variable bound by
an expression type signature: [a1] at <interactive>:7:1
In the expression: True
In the expression: [True] :: forall a. [a]
In an equation for `it': it = [True] :: forall a. [a]
Prelude> ['a'] :: (forall a. [a])
<interactive>:8:2:
Couldn't match expected type `a1' with actual type `Char'
`a1' is a rigid type variable bound by
an expression type signature: [a1] at <interactive>:8:1
In the expression: 'a'
In the expression: ['a'] :: forall a. [a]
In an equation for `it': it = ['a'] :: forall a. [a]
Prelude> [\x -> x] :: (forall a. [a])
<interactive>:9:2:
Couldn't match expected type `a1' with actual type `t0 -> t0'
`a1' is a rigid type variable bound by
an expression type signature: [a1] at <interactive>:9:1
The lambda expression `\ x -> x' has one argument,
but its type `a1' has none
In the expression: \ x -> x
In the expression: [\ x -> x] :: forall a. [a]
2014년 06월 15일 12:47, Gábor Lehel 쓴 글:
> In other words instances for forall-types, such as:
>
> instance Foo (forall a. [a]) where ...
>
> It feels obvious to me that there *would* be problems with this, but I'm
> curious about what, exactly, they are.
>
> Could someone familiar with the matter either elaborate on them, or
> refer me to an existing explanation, a previous discussion, or something
> of the sort?
>
> I *don't* have any kind of use case in mind, I'm merely seeking a better
> understanding of the type-system issues involved.
>
> (I attempted Google, but didn't have much success.)
>
> Thanks in advance.
More information about the Haskell-Cafe
mailing list