|
RE: higher-order typing errors: msg#00046lang.haskell.glasgow.bugs
Because GHC does not allow you to instantiate a polymorphic type variable with a polymorphic type. For example, you can have Maybe Int Maybe (Int -> Int) but not Maybe (forall a. a->a) The Maybe type is defined thus data Maybe b = Nothing | Just b so the type (Maybe (forall a. a->a)) would instantiate 'b' with (forall a. a->a), and GHC just doesn't allow that. In your program, its the tuple type data (,) a b = (,) a b Admittedly the error message is not especially helpful. Why does GHC have this restriction? Because type inference is much, much harder without it. There may be a way to lift it, but I don't yet know what it is. To get around it, define your own data type: data MyPr = MyPr (forall a.a->a) (forall a.a->a) swap1 :: MyPr -> MyPr Simon | -----Original Message----- | From: Dean Herington [mailto:heringto@xxxxxxxxxx] | Sent: 22 January 2003 23:03 | To: glasgow-haskell-bugs@xxxxxxxxxxx | Subject: higher-order typing errors | | I don't understand why GHC (I was using 5.04.2) should reject these two | programs. | | ======== | | {-# OPTIONS -fglasgow-exts #-} | | swap1 :: (forall a. a -> a, forall a. a -> a -> a) | -> (forall a. a -> a -> a, forall a. a -> a) | swap1 (a, b) = (b, a) | | yields: | | Bug2.hs:3: parse error on input `,' | | ======== | | {-# OPTIONS -fglasgow-exts #-} | | swap2 :: ((forall a. a -> a), (forall a. a -> a -> a)) | -> ((forall a. a -> a -> a), (forall a. a -> a)) | swap2 (a, b) = (b, a) | | yields: | | Bug2.hs:3: | Illegal polymorphic type: forall a. a -> a | In the type: (forall a. a -> a, forall a. a -> a -> a) | -> (forall a. a -> a -> a, forall a. a -> a) | While checking the type signature for `swap2' | | | _______________________________________________ | Glasgow-haskell-bugs mailing list | Glasgow-haskell-bugs@xxxxxxxxxxx | http://www.haskell.org/mailman/listinfo/glasgow-haskell-bugs
|
|
| <Prev in Thread] | Current Thread | [Next in Thread> |
|---|---|---|
| Previous by Date: | [ ghc-Bugs-672813 ] bad type does bad things, SourceForge.net |
|---|---|
| Next by Date: | RE: funny bold ouput in GHCI, Simon Peyton-Jones |
| Previous by Thread: | higher-order typing errors, Dean Herington |
| Next by Thread: | Re: higher-order typing errors, Tomasz Zielonka |
| Indexes: | [Date] [Thread] [Top] [All Lists] |
| News | FAQ | advertise |