<html><head></head><body><p dir="ltr">I am trying to implement ant colony optimization algorithm (or any other similar simulation) . In procedural language I would keep the world map in 2D matrix that provides O(1) collision check and O(1) ant position change. </p>
<p dir="ltr">Should I try to implement this in haskell in the same way (2d mutable matrix)? If yes,  what data structure should I use?<br>
If not,  how can I achieve the same performance as in procedural style? </p>
<p dir="ltr">(The memory usage is also important.) </p>
<p dir="ltr">Thank you for any tips. </p>
<p dir="ltr">King regards, </p>
<p dir="ltr">Ford</p>
<p dir="ltr"><!-- tmjah_g_1299s -->Odesláno z <a href="http://www.bluemail.me/r">BlueMail<!-- tmjah_g_1299e --></a><br><br></p>
<div class="gmail_quote" >7. 7. 2016, 11:40 AM, Norbert Melzer <<a href="mailto:timmelzer@gmail.com" target="_blank">timmelzer@gmail.com</a>> napsal/a:<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="blue"><br>OxFord writes:<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;"> Hello,<br><br> Why is there no default O(1) random access list data structure in haskell<br> (for example clojure has [] vector). I would expect that this kind of data<br> structure is used very often, so you shouldn't need to import one yourself.<br></blockquote><br>Whenever I try to reach for something with O(1) random access, then I<br>have used imperative languages for too long ;) In most cases I am able<br>to rewrite my algorithms to work by iterating instead of random access.<br>And if I do not come up with such an algorithm, I then do realize most<br>of the time, that I do want to have a Map or Set with a certain<br>Key-Type, which is very unlikely to be Num.<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;"> Is it safe to assume that '
reverse [1, 2, 3, 4, 5] ' is O(1) ?<br></blockquote><br>It is not. Reversing in constant time is impossible without dooing nasty<br>hacks, and make it necessary to not only save distinct elements, but its<br>reading direction in addition.<br><br>Also to make this actually happen you need something in the spirit of<br>a C Array or a doubly linked list.<br><br>Also you will get in trouble as soon as you want to change an element in<br>the reversed collection, but not in the original one.<br><br>As soon as you want distinct containers you need to copy, and copying is<br>O(n) at least.<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;"> Is it safe to assume that main =<br> x = [1, 2, 3, 4, 5]<br> x = reverse reverse x<br> won't use more space than for the initial [1, 2, 3, 4, 5] list? (No copy of<br> x)<br></blockquote><br>According to my observations it is not safe to assume anything about<br>memory in GC'd
languages.<br><br><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;"> Why is array indexeded by ! and list by !!. Shouldn't they be both<br> instances of something like Indexable?<br></blockquote><br>Because indexed access is always something you should think about, and<br>for lists you should think about it even twice. Thats just a guess though.<br><hr><br>Beginners mailing list<br>Beginners@haskell.org<br><a href="http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners">http://mail.haskell.org/cgi-bin/mailman/listinfo/beginners</a><br></pre></blockquote></div></body></html>