[Haskell-cafe] Question about kinds

Ryan Ingram ryani.spam at gmail.com
Sat Jun 7 04:50:37 EDT 2008


"type" declarations are not first-class; treat them more like macro
expansions.  In particular, you cannot make a function polymorphic
over a type declaration.

You can make this typecheck using a "data" or "newtype" declaration for Id:

newtype Id x = Identity x
(or)
data Id x = Identity x

You do need to wrap/unwrap the "Identity" constructor then.

  -- ryan

On Fri, Jun 6, 2008 at 3:41 PM, Klaus Ostermann <ko at daimi.au.dk> wrote:
>
> Why does the code below not pass the type checker?
>
> If I could explictly parameterize y with the type constructor Id (as e.g. in
> System F), then 'y Id' should have the type Int -> Int
> and hence "y Id x" should be OK, but with Haskell's implicit type parameters
> it does not work.
>
> So, how can I make this work?
>
> Klaus
> ------------
>
> type Id a = a
>
> x :: Id Int
> x = undefined
>
> y :: (a Int) -> (a Int)
> y = undefined
>
> test = y x
>
> Error:
>  Couldn't match expected type `a Int' against inferred type `Id Int'
>  In the first argument of `y', namely `x'
>  In the expression: y x
>  In the definition of `test': test = y x


More information about the Haskell-Cafe mailing list