[Haskell-beginners] The following is supposed to be initializing a 2D array but it doesn't seem to work.
KC
kc1956 at gmail.com
Tue Jul 31 23:52:17 CEST 2012
newArr :: (Ix i) => i -> i -> e -> Array i e
newArr n m x = listArray (n,m) (repeat
<http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html#v:repeat>
x)
-----
Prelude <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html>
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 <http://haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html>
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.
--
--
Regards,
KC
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/beginners/attachments/20120731/cf2b0c59/attachment-0001.htm>
More information about the Beginners
mailing list