[Haskell-beginners] How to call popCnt64#?

John Ky newhoggy at gmail.com
Tue Mar 22 23:03:10 UTC 2016


Hi Marcin,

That explanation helps.  Thanks!

-John

On Tue, 22 Mar 2016 at 18:25 Marcin Mrotek <marcin.jan.mrotek at gmail.com>
wrote:

> 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
> _______________________________________________
> Beginners mailing list
> Beginners at haskell.org
> http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.haskell.org/pipermail/beginners/attachments/20160322/2550eb63/attachment.html>


More information about the Beginners mailing list