haskell-handbook icon indicating copy to clipboard operation
haskell-handbook copied to clipboard

How to use actual arrays, 1D or 2D, with O(1) access and mutation complexity

Open Martinsos opened this issue 2 years ago • 3 comments
trafficstars

I still don't know how to work with arrays in Haskell that are fast like in other languages! I would like to write a tutorial that explains this but for the beginners, and is as simple as possible, not assuming you know what ST monad is and similar, but instead shows with very good examples how to do it -> ideally I would just follow those examples and get it done.

I asked a bit around and was told that this probably has to do with ST monad, so maybe I should look in that direction.

I also found out there are Vector and Array libraries which can serve for this although the are somewhat different.

Some potential resources:

  • https://www.reddit.com/r/haskell/comments/1031s81/optimising_haskell_2_swapping_set_for_array/?utm_source=share&utm_medium=android_app&utm_name=androidcss&utm_term=2&utm_content=share_button

Martinsos avatar Jan 06 '23 19:01 Martinsos

Potential name of the blog post: "Beyond Lists".

Martinsos avatar Jan 09 '23 18:01 Martinsos

Vectors are intersting, since they have O(1) access. But mutation is still not O(1). Certainly address them though.

Martinsos avatar Jan 09 '23 18:01 Martinsos

I read in a blog post:

💡 Haskell has mutable constructs (such as STArray and IORef), which you can use when you need mutability.

Martinsos avatar Feb 14 '23 13:02 Martinsos