[Haskell-cafe] Re: Non-existing types in existential quantification?

Daniel Fischer daniel.is.fischer at web.de
Sun Oct 3 08:10:45 EDT 2010


On Sunday 03 October 2010 10:43:24, Henning Thielemann wrote:
> On Sun, 3 Oct 2010, Ben Franksen wrote:
> > Christopher Done wrote:
> >> Consider the following program:
> >>
> >> main = putStrLn $ show $ length [undefined :: a,undefined :: b]
> >>
> >> A concrete type of the element in list doesn't need to be determined
> >> at runtime, or any time. a unifies with b, and that unifies with x in
> >> length :: [x] -> Int.
> >
> > A simpler example is
> >
> >  main = print Nothing
>
> This seems to be a different example, because "GHCi -Wall" says that the
> type variable defaults to (). Thus 'Nothing' has monomorphic type at
> runtime. The difference is certainly that 'print' requires a Show
> instance, whereas Christopher's example does not require a type
> constraint.

Yup.

Prelude> print $ length [undefined :: a, undefined :: b]
2
Prelude> print $ length [undefined :: a, undefined :: Num b => b]

<interactive>:1:32:
    Warning: Defaulting the following constraint(s) to type `Integer'
             `Num a'
               arising from an expression type signature at 
<interactive>:1:32-54
    In the expression: undefined :: (Num b) => b
    In the first argument of `length', namely
        `[undefined :: a, undefined :: (Num b) => b]'
    In the second argument of `($)', namely
        `length [undefined :: a, undefined :: (Num b) => b]'
2
Prelude> print $ length [undefined :: a, undefined :: Num b => c -> b]

<interactive>:1:32:
    Warning: Defaulting the following constraint(s) to type `Integer'
             `Num b'
               arising from an expression type signature at 
<interactive>:1:32-59
    In the expression: undefined :: (Num b) => c -> b
    In the first argument of `length', namely
        `[undefined :: a, undefined :: (Num b) => c -> b]'
    In the second argument of `($)', namely
        `length [undefined :: a, undefined :: (Num b) => c -> b]'
2

At runtime, a type variable has to be either unconstrained or instantiated 
with a concrete type?



More information about the Haskell-Cafe mailing list