[Haskell-beginners] Meaning of '!' in record defintion? UNPACK?

Daniel Fischer daniel.is.fischer at web.de
Thu Feb 26 06:55:56 EST 2009


Am Donnerstag, 26. Februar 2009 12:36 schrieb Magnus Therning:
> Are there any guarantees here, or is it just me telling the compiler
> to please do what I say, but the compiler can decide not to follow my
> wishes?

I don't think there are guarantees, as the section ends with:

"If a field cannot be unpacked, you will not get a warning, so it might be an 
idea to check the generated code with -ddump-simpl.

See also the -funbox-strict-fields flag, which essentially has the effect of 
adding {-# UNPACK #-} to every strict constructor field."

But it should be very likely to do what you want (of course, always compile 
with -O or -O2).

> Is address aligning predictable?

Absolutely no idea, sorry.

>
> I'm basically wondering if it'd be possible to to use this mechanism
> to avoid using FFI when reading data that basically is a dump of
> structs in a C program.

I doubt it, as I understand it, with {-# UNPACK #-}, you'll have the layout

constuctor rawdata

and the C structs won't have the constructor.

>
> /M

Cheers,
Daniel



More information about the Beginners mailing list