Using unboxed integers

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|

Using unboxed integers

Richard A. O'Keefe
I have x, y :: Int#
I expect that x <=# y :: Bool
but ghc 7.8 says
     Couldn't match expected type ‘Bool’ with actual type ‘Int#’
     In the expression: x <=# y
     In an equation for ‘b’: b = x <=# y

I have MagicHash and I've imported the right modules so that
<=# is recognised as *something*, but at this point I'm baffled.

I'm also not clear on how I can show an Int#.


_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: Using unboxed integers

Rahul Muttineni
Use the isTrue# function which is made visible by importing GHC.Base.

isTrue# (x <=# y) :: Bool

You can show an Int# by wrapping it up in an I# data constructor and applying show to it:

x# :: Int#
show (I# x#) ::String

You can make the I# data constructor visible via GHC.Base like above. 

Hope that helps!
Rahul


On Wed, Nov 2, 2016 at 11:20 AM, Richard A. O'Keefe <[hidden email]> wrote:
I have x, y :: Int#
I expect that x <=# y :: Bool
but ghc 7.8 says
    Couldn't match expected type ‘Bool’ with actual type ‘Int#’
    In the expression: x <=# y
    In an equation for ‘b’: b = x <=# y

I have MagicHash and I've imported the right modules so that
<=# is recognised as *something*, but at this point I'm baffled.

I'm also not clear on how I can show an Int#.


_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.



--
Rahul Muttineni

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: Using unboxed integers

Richard A. O'Keefe
import GHC.Base
isTrue# (comparison)
show (I# x#)
worked.  Thank you very much.

This made a barely measurable difference to my program, so I now that
I know how to use unboxed integers, I can forget again.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.
Reply | Threaded
Open this post in threaded view
|

Re: Using unboxed integers

Zemyla

If you look at the Core GHC produces (with -ddump-simpl), you'll probably see that the Ints have been unboxed for as many operations as possible, so manual unboxing won't make that much difference.


On Nov 2, 2016 1:15 AM, "Richard A. O'Keefe" <[hidden email]> wrote:
import GHC.Base
isTrue# (comparison)
show (I# x#)
worked.  Thank you very much.

This made a barely measurable difference to my program, so I now that
I know how to use unboxed integers, I can forget again.
_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.

_______________________________________________
Haskell-Cafe mailing list
To (un)subscribe, modify options or view archives go to:
http://mail.haskell.org/cgi-bin/mailman/listinfo/haskell-cafe
Only members subscribed via the mailman list are allowed to post.