Random questions after a long haskell coding day

Simon Marlow simonmar@microsoft.com
Mon, 28 Jan 2002 15:37:07 -0000

> Any thumb rule for using arrays? I'm expecting access to be=20
> O(1), it is right?

In GHC, yes.

> Need to have a set of data, and I just want to get random=20
> elements from that=20
> Set, arrays seem like a good solution... am I right?

If you're building it once and doing lots of access, then Haskell arrays
are a good choice.

> DiffArrays... aren't they supposed to be just like Arrays=20
> expect for the (//)=20
> behaviour (and accum and accumArray....), If so, why is there no Show=20
> instance for them? Or Functor instance?

We added the Show instances post-5.02.2, but they are still missing
Functor and Read instances.  Thanks for pointing this out; I'll take a
look before the next release.

> Unboxed types... Ghci
> > f n  =3D  3#=20
> loads ok and,
> Test> :t f
> forall t. t -> PrelGHC.Int#
> nice... now this:
> > f :: Int -> Int#
> > f n  =3D  3#=20
> when trying to load I get:
> Test.hs:3: Type constructor or class not in scope: `Int#'
> Failed, modules loaded: none.
> What  am I missing here? Tried Int#, PrelGHC.Int... nothing worked...
> and Ghci also didn't know about (+#) either...=20

The type constructor Int# isn't in scope (there's a clue in the error
message: GHC used PrelGHC.Int# rather than the unqualified form, because
it isn't in scope).  Int# and the other unboxed primitives types and
operations can be imported from module GlaExts in package lang
(recommended) or PrelGHC (fragile).