Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8741063
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T11:14:30+00:00 2026-06-13T11:14:30+00:00

The {-# UNPACK #-} pragma tells the compiler to eliminate redundant constructors. Quoting Haskell

  • 0

The {-# UNPACK #-} pragma tells the compiler to eliminate redundant constructors. Quoting Haskell wiki:

For example, given this:

data T = T {-# UNPACK #-} !(Int,Float)

GHC will represent the type T like this:

data T = T Int Float

eliminating the tuple. This is commonly used to put unboxed Ints directly in a constructor:

data T = T {-# UNPACK #-} !Int

will be represented as

data T = T Int#

I was wondering, does this also work when the field to be unpacked is polymorphic? For example, if I define

data S' a   = S String {-# UNPACK #-} !a

type S1     = S' Int
newtype S2  = S2 (S' Int)

will functions that work with S1 or S2 be optimized?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T11:14:31+00:00Added an answer on June 13, 2026 at 11:14 am

    Quoting from Don’s blog about unpacking

    It does not make sense for polymorphic fields, since they have variable size, and the compiler does not (except in very specific circumstances) have access to information about what types are in use.

    Also you can read Tibell’s reply to mailing list.

    Unfortunately unpacking doesn’t work for polymorphic fields (the new warning for ineffective unpack pragmas in GHC head should warn about this) …

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am getting this: _format_ = 7c7sc print struct.unpack(self._format_, data) gives ('\x7f', 'E', 'L',
I need to unpack binary data that is encoded rather exotically: a 32 bit
How can I do this Perl code in PHP? print unpack (H*, pack (B*,
How can I unpack a 4byte binary file, store like the following example, to
How to unpack() the first structure in this list ? I want the second
I need the Python analog for this Perl string: unpack(nNccH*, string_val) I need the
What format I should use in struct.unpack to decode data packed in perl using
I am trying to use struct.unpack() to take apart a data record that ends
for example in Python: number = struct.unpack('!L', socket.inet_aton(ip))[0] ip = socket.inet_ntoa(struct.pack('!L',number))
struct.unpack will unpack data into a tuple. Is there an equivalent that will store

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.