Unpacking polymorphic fields

Hi, Suppose I have the following two datatypes. data B = B {-# UNPACK #-} !Int data C a = C {-# UNPACK #-} !Char !a If I have a strict function: test :: C B -> IO () I want it to be worker-wrapper-transformed into: $wtest :: Char# -> Int# -> State# RealWorld -> (# State# RealWorld, () #) but GHC actually generates something like: $wtest :: Char# -> B -> State# RealWorld -> (# State# RealWorld, () #) The question is: is there any way to ask GHC to produce the former? If the field is not polymorphic, UNPACK pragma can be used for this, but it does not work in this case. If there is no such way, would it be a reasonable "feature request" to add one? Regards, Takano Akio

Can you send a small example program for 'test'? | -----Original Message----- | From: glasgow-haskell-users-bounces@haskell.org [mailto:glasgow-haskell-users-bounces@haskell.org] | On Behalf Of Takano Akio | Sent: 15 November 2006 10:55 | To: glasgow-haskell-users@haskell.org | Subject: Unpacking polymorphic fields | | Hi, | | Suppose I have the following two datatypes. | | data B = B {-# UNPACK #-} !Int | data C a = C {-# UNPACK #-} !Char !a | | If I have a strict function: | | test :: C B -> IO () | | I want it to be worker-wrapper-transformed into: | | $wtest :: Char# -> Int# -> State# RealWorld -> (# State# RealWorld, () #) | | but GHC actually generates something like: | | $wtest :: Char# -> B -> State# RealWorld -> (# State# RealWorld, () #) | | The question is: is there any way to ask GHC to produce the former? | If the field is not polymorphic, UNPACK pragma can be used for this, but | it does not work in this case. If there is no such way, would | it be a reasonable "feature request" to add one? | | Regards, | Takano Akio | _______________________________________________ | Glasgow-haskell-users mailing list | Glasgow-haskell-users@haskell.org | http://www.haskell.org/mailman/listinfo/glasgow-haskell-users

On Wed, 15 Nov 2006 10:58:23 +0000
Simon Peyton-Jones
Can you send a small example program for 'test'?
Here's an example: module Test(test) where data B = B {-# UNPACK #-} !Int data C a = C {-# UNPACK #-} !Char !a printB :: B -> IO () printB (B x) = print x test :: C B -> IO () test (C c b) = print c >> printB b

No, there's no easy way (that I can see) to achieve what you want. The problem is that the way to unpack C depends on how you instantiate 'a'. So you need a specialised variant of the actual data constructor C, one for each instantiation of 'a'. (Well, one for each "shape" of instantiation anyway.) GHC doesn't currently generate specialised data constructors. In principle one could do that, but it's not an easy step. Simon | -----Original Message----- | From: glasgow-haskell-users-bounces@haskell.org [mailto:glasgow-haskell-users- | bounces@haskell.org] On Behalf Of Takano Akio | Sent: 15 November 2006 10:55 | To: glasgow-haskell-users@haskell.org | Subject: Unpacking polymorphic fields | | Hi, | | Suppose I have the following two datatypes. | | data B = B {-# UNPACK #-} !Int | data C a = C {-# UNPACK #-} !Char !a | | If I have a strict function: | | printB :: B -> IO () | printB (B x) = print x | | test :: C B -> IO () | test (C c b) = print c >> printB b | | | I want it to be worker-wrapper-transformed into: | | $wtest :: Char# -> Int# -> State# RealWorld -> (# State# RealWorld, () #) | | but GHC actually generates something like: | | $wtest :: Char# -> B -> State# RealWorld -> (# State# RealWorld, () #) | | The question is: is there any way to ask GHC to produce the former? | If the field is not polymorphic, UNPACK pragma can be used for this, but | it does not work in this case. If there is no such way, would | it be a reasonable "feature request" to add one? | | Regards, | Takano Akio | _______________________________________________ | Glasgow-haskell-users mailing list | Glasgow-haskell-users@haskell.org | http://www.haskell.org/mailman/listinfo/glasgow-haskell-users
participants (2)
-
Simon Peyton-Jones
-
Takano Akio