
12 Mar
2002
12 Mar
'02
6:23 a.m.
I would like to print an unboxed value to the screen. But to use "show" on a type it has to be boxed. How do I rebox an unboxed type? Sorry if the answer to this is obvious - I have spent quite some time looking for the solution.
You need to know what kind of box - the unboxed value no longer has the `tag' saying what type it is.
Boxed Ints, for example, are declared like this in the prelude:
data Int = I# Int#
So to build an Int from an Int#, simply say (I# x), like this:
case (+# 1# 42#) of {
x -> show (I# x)
}
(you'll probably need to import whichever module has the definition of Int in it).
Hope this helps..
--KW 8-)
--
Keith Wansbrough