[Haskell-cafe] Haskell vs GC'd imperative languages, threading, parallelizeability (is that a word? :-D )

Stefan O'Rear stefanor at cox.net
Fri Aug 10 04:05:41 EDT 2007

On Fri, Aug 10, 2007 at 04:00:01PM +0800, Hugh Perkins wrote:
> On 8/10/07, Donald Bruce Stewart <dons at cse.unsw.edu.au> wrote:
> >
> > It's using bit arrays.
> >
> Well I'm a total Haskell newbie, and you're using Haskell to write
> imperative code, so it's really hard for me to read, but looking at your
> code, you have:
> (IOUArray Int Bool) -- an array of Bool
> Bool is a 32-bit value in Haskell AFAIK?  (or possibly a machine-dependent
> sized value, but certainly not a bit?)

Bool is 32 bits, but Don is using UArray.  UArray is not parametric in
the element type, which means it's less generally useful (no UArray of
Complex Double, for instance), but conversely it is able to use more
efficient representations depending on the type.

from Data.Array.Base:

instance MArray (STUArray s) Bool (ST s) where
    unsafeRead (STUArray _ _ marr#) (I# i#) = ST $ \s1# ->
        case readWordArray# marr# (bOOL_INDEX i#) s1# of { (# s2#, e# #) ->
        (# s2#, (e# `and#` bOOL_BIT i#) `neWord#` int2Word# 0# #) }

Okay, you probably can't read that (it's too ugly for me to *want* to
read it), but the use of and# should stand out.

bOOL_BIT computes a bitmask, bOOL_INDEX divides by 8.

-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 189 bytes
Desc: Digital signature
Url : http://www.haskell.org/pipermail/haskell-cafe/attachments/20070810/a3af22b9/attachment.bin

More information about the Haskell-Cafe mailing list