On Fri, 2008-06-06 at 15:41 -0700, Klaus Ostermann 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
On Fri, Jun 6, 2008 at 4:41 PM, Klaus Ostermann [EMAIL PROTECTED] wrote:
type Id a = a
x :: Id Int
x = undefined
y :: (a Int) - (a Int)
y = undefined
In a Int, a refers to any type constructor, not any type function.
So the best you can do is:
newtype Id a = Id a
-- rest as before
Luke
On Fri, Jun 06, 2008 at 03:41:07PM -0700, Klaus Ostermann 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
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
short answer: use newtype instead of type (and check the
language spec for the difference between the two).
Why does the code below not pass the type checker?
because of the type error?-) seriously, though, it is useful to
accompany such questions with some indication of what you're
trying to
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