New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Issue with Array.append #205

Closed
jheiling opened this Issue Apr 2, 2015 · 5 comments

Comments

Projects
None yet
5 participants
@jheiling

jheiling commented Apr 2, 2015

There seems to be an issue with Array.append:

I have the following functions for creating a jagged array and turning it into a regular array:

initialize : Int -> Int -> (Int -> Int -> a) -> Array(Array a)
initialize l1 l2 f = Array.initialize l1 (\i1 -> Array.initialize l2 (f i1))

toArray : Array(Array a) -> Array a
toArray = Array.foldl (flip Array.append) Array.empty

If I just call

xs = initialize 3 3 (,)

it works as expected and xs is

Array.fromList [Array.fromList [(0,0),(0,1),(0,2)],Array.fromList [(1,0),(1,1),(1,2)],Array.fromList [(2,0),(2,1),(2,2)]]

But if I call

xs' = toArray xs

later, xs will be

Array.fromList [Array.fromList [(0,0),(0,1),(0,2),(1,0),(1,1),(1,2),(2,0),(2,1),(2,2)],Array.fromList [(1,0),(1,1),(1,2)],Array.fromList [(2,0),(2,1),(2,2)]]

afterwards.

Here's a full example showning the bug:

import Array
import Array (Array)
import Graphics.Element (..)
import Text (..)

initialize : Int -> Int -> (Int -> Int -> a) -> Array(Array a)
initialize l1 l2 f = Array.initialize l1 (\i1 -> Array.initialize l2 (f i1))

toArray : Array(Array a) -> Array a
toArray = Array.foldl (flip Array.append) Array.empty

xs = initialize 3 3 (,)
xs' = toArray xs

main = 
  [ asText xs
  , asText xs' ]
  |> flow down
@sindikat

This comment has been minimized.

Show comment
Hide comment
@sindikat

sindikat Aug 25, 2015

I think I have the same bug with using Array.Extra.resizelRepeat, which uses Array.append and Array.repeat. There's something going on from JavaScript side.

sindikat commented Aug 25, 2015

I think I have the same bug with using Array.Extra.resizelRepeat, which uses Array.append and Array.repeat. There's something going on from JavaScript side.

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Jun 25, 2016

Member

Closing in favor of #649 which will track all array issues and progress on a new implementation.

Member

evancz commented Jun 25, 2016

Closing in favor of #649 which will track all array issues and progress on a new implementation.

@evancz evancz closed this Jun 25, 2016

@JulianLeviston

This comment has been minimized.

Show comment
Hide comment
@JulianLeviston

JulianLeviston Mar 22, 2017

Any progress on the new implementation? #649 doesn't seem to include any updates as at now.

JulianLeviston commented Mar 22, 2017

Any progress on the new implementation? #649 doesn't seem to include any updates as at now.

@Skinney

This comment has been minimized.

Show comment
Hide comment
@Skinney

Skinney Mar 22, 2017

Contributor

The new implementation lives at https://github.com/Skinney/elm-array-exploration. It can be used in your code today. All it really needs is a final look over before it's ready to be merged. Hopefully I'll find the time to do that soon.

Contributor

Skinney commented Mar 22, 2017

The new implementation lives at https://github.com/Skinney/elm-array-exploration. It can be used in your code today. All it really needs is a final look over before it's ready to be merged. Hopefully I'll find the time to do that soon.

@JulianLeviston

This comment has been minimized.

Show comment
Hide comment
@JulianLeviston

JulianLeviston Mar 23, 2017

@Skinney awesome. Thanks :)

JulianLeviston commented Mar 23, 2017

@Skinney awesome. Thanks :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment