[Haskell-beginners] How to call popCnt64#?

Marcin Mrotek marcin.jan.mrotek at gmail.com
Tue Mar 22 07:25:15 UTC 2016


Hi,

In general, the problem is that GHCi is attempting to call `show` on the
results of expressions you type in, but `show` (like any other polymorphic
function; though you can look into "levity polymorphism" if you want to
know more) can only accept values of types of kind * (boxed, lifted) - so
it can print Word, but not Word#.

If you wanted to stay in GHCi, you can do it like:

Prelude> import GHC.Prim
Prelude GHC.Prim> import GHC.Types
Prelude GHC.Prim GHC.Types> :set -XMagicHash
Prelude GHC.Prim GHC.Types> :t W#
W# :: Word# -> Word
Prelude GHC.Prim GHC.Types> :t popCnt64#
popCnt64# :: Word# -> Word#
Prelude GHC.Prim GHC.Types> let foo = (1 :: Word)
Prelude GHC.Prim GHC.Types> :set -XBangPatterns
Prelude GHC.Prim GHC.Types> let !(W# w) = foo in W# (popCnt64# w)
1

Best regards,
Marcin Mrotek
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160322/3ecebfb8/attachment.html>


More information about the Beginners mailing list