[Haskell-cafe] The following is supposed to be initializing a 2D array but it doesn't seem to work.
Ivan Lazar Miljenovic
ivan.miljenovic at gmail.com
Wed Aug 1 00:14:49 CEST 2012
On 1 August 2012 07:52, KC <kc1956 at gmail.com> wrote:
> newArr :: (Ix i) => i -> i -> e -> Array i e
>
> newArr n m x = listArray (n,m) (repeat x)
>
>
> -----
>
> Prelude Data.Array> newArr 0 10 0
>
> array (0,10)
> [(0,0),(1,0),(2,0),(3,0),(4,0),(5,0),(6,0),(7,0),(8,0),(9,0),(10,0)]
>
>
> Prelude Data.Array> newArr (0,0) (5,5) 0
>
> array ((0,0),(5,5))
> [((0,0),0),((0,1),0),((0,2),0),((0,3),0),((0,4),0),((0,5),0),((1,0),0),((1,1),0),((1,2),0),((1,3),0),((1,4),0),((1,5),0),((2,0),0),((2,1),0),((2,2),0),((2,3),0),((2,4),0),((2,5),0),((3,0),0),((3,1),0),((3,2),0),((3,3),0),((3,4),0),((3,5),0),((4,0),0),((4,1),0),((4,2),0),((4,3),0),((4,4),0),((4,5),0),((5,0),0),((5,1),0),((5,2),0),((5,3),0),((5,4),0),((5,5),0)]
>
>
> All I am getting is this:
> array ((1,5),(1,5)) [((1,5),1.0)]
>
> Maybe the behaviour of ghc was changed since the article was written.
Works for me:
$ghci
GHCi, version 7.4.2: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> :m +Data.Array
Prelude Data.Array> let newArr n m x = listArray (n,m) (repeat x)
Prelude Data.Array> newArr (0,0) (5,5) 0
array ((0,0),(5,5))
[((0,0),0),((0,1),0),((0,2),0),((0,3),0),((0,4),0),((0,5),0),((1,0),0),((1,1),0),((1,2),0),((1,3),0),((1,4),0),((1,5),0),((2,0),0),((2,1),0),((2,2),0),((2,3),0),((2,4),0),((2,5),0),((3,0),0),((3,1),0),((3,2),0),((3,3),0),((3,4),0),((3,5),0),((4,0),0),((4,1),0),((4,2),0),((4,3),0),((4,4),0),((4,5),0),((5,0),0),((5,1),0),((5,2),0),((5,3),0),((5,4),0),((5,5),0)]
Prelude Data.Array>
Which article are you referring to?
>
>
> --
> --
> Regards,
> KC
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
--
Ivan Lazar Miljenovic
Ivan.Miljenovic at gmail.com
http://IvanMiljenovic.wordpress.com
More information about the Haskell-Cafe
mailing list