Prefix form of unboxed tuple

Hi, The following works fine: ghci -fglasgow-exts Prelude> case (# 1 , 2 #) of (# a , b #) -> error $ show (a,b) *** Exception: (1,2) You might expect there to be a prefix form of the unboxed tuple: Prelude> case (#,#) 1 2 of (# a , b #) -> error $ show (a,b) <interactive>:1:7: parse error on input `,' But there isn't. I've added special code into the Yhc code generator to deal with this particular constructor, so it no longer effects me. Thanks Neil

On Fri, Jul 06, 2007 at 11:26:00AM +0100, Neil Mitchell wrote:
ghci -fglasgow-exts Prelude> case (# 1 , 2 #) of (# a , b #) -> error $ show (a,b) *** Exception: (1,2)
You might expect there to be a prefix form of the unboxed tuple:
Prelude> case (#,#) 1 2 of (# a , b #) -> error $ show (a,b) <interactive>:1:7: parse error on input `,'
But there isn't. I've added special code into the Yhc code generator to deal with this particular constructor, so it no longer effects me.
Well, what would the type of (#,#) be? unboxed tuples can hold both boxed and unboxed values, so some sort of kind polymorphism would be needed to type the prefix form properly. John -- John Meacham - ⑆repetae.net⑆john⑈

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 John Meacham wrote:
On Fri, Jul 06, 2007 at 11:26:00AM +0100, Neil Mitchell wrote:
ghci -fglasgow-exts Prelude> case (# 1 , 2 #) of (# a , b #) -> error $ show (a,b) *** Exception: (1,2)
You might expect there to be a prefix form of the unboxed tuple:
Prelude> case (#,#) 1 2 of (# a , b #) -> error $ show (a,b) <interactive>:1:7: parse error on input `,'
But there isn't. I've added special code into the Yhc code generator to deal with this particular constructor, so it no longer effects me.
Well, what would the type of (#,#) be? unboxed tuples can hold both boxed and unboxed values, so some sort of kind polymorphism would be needed to type the prefix form properly.
In GHC, some special functions have kind polymorphism http://hackage.haskell.org/trac/ghc/wiki/IntermediateTypes error :: forall a:?. String -> a (->) :: ?? -> ? -> * (\(x::t) -> ...) Here t::?? (i.e. not unboxed tuple) (and http://hackage.haskell.org/trac/ghc/changeset/2807 "But the 'real' type of error is: forall bv. forall a:Type bv. String -> a ") Or just saying it's illegal to partially apply (#,#) - which I believe is how (some of) GHC's primops work. Isaac -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.6 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iD8DBQFGjj2rHgcxvIWYTTURAp03AJ4/kgTzuN6PHp5QFTOQBKJIKa8QtQCeLvjm hh9TO2NDFzZ2N+FYsgOORGU= =6GJm -----END PGP SIGNATURE-----

| You might expect there to be a prefix form of the unboxed tuple: | | Prelude> case (#,#) 1 2 of (# a , b #) -> error $ show (a,b) | <interactive>:1:7: parse error on input `,' | | But there isn't. No real reason why not. If you write foo :: a -> b -> (# a,b #) foo x y = (# x, y #) then foo should work just fine. So what you want needs two things: * We would have to define a collection of such functions in the Prelude (see Data.Tuple, for the (,,,,) functions). * We'd have to do is to make the parser understand '(#,,,#)'. Do add a feature request if you like. (And/or implement it!) It'd be a good "rounding out" thing. Another feature I'd like is for unboxed tuples to be more first class. For example, we don't currently allow f :: (# a, b #) -> ... But there's no real reason why not; we could transform them away just before code generation. That would eliminate all special cases for unboxed tuples, except the constraints that apply to all unboxed types (notably: you can't instantiate a type variable with an unboxed type; unboxed types are strict). If you add a feature request, add that too! Simon

Hi
No real reason why not. If you write
foo :: a -> b -> (# a,b #) foo x y = (# x, y #)
then foo should work just fine. So what you want needs two things:
Do add a feature request if you like. (And/or implement it!) It'd be a good "rounding out" thing.
Another feature I'd like is for unboxed tuples to be more first class. For example, we don't currently allow f :: (# a, b #) -> ...
Ah, this tripped me up for a long time this afternoon. The error message I was getting was not particularly helpful - I discovered that by putting this type in a constructor and projecting into and out of the constructor things worked. I never realise that the unboxed tuple in a type signature just didn't work. Thanks Neil

Hello Simon, Friday, July 6, 2007, 6:57:26 PM, you wrote:
Another feature I'd like is for unboxed tuples to be more first class. For example, we don't currently allow f :: (# a, b #) -> ...
one particular feature i wanted in my fast io/serialization libs is ability to return unboxed tuple from IO action. is this also possible? -- Best regards, Bulat mailto:Bulat.Ziganshin@gmail.com

| one particular feature i wanted in my fast io/serialization libs is | ability to return unboxed tuple from IO action. is this also possible? No -- that's an example of instantiating a polymorphic type with an unboxed one. Sorry. S
participants (5)
-
Bulat Ziganshin
-
Isaac Dupree
-
John Meacham
-
Neil Mitchell
-
Simon Peyton-Jones