{"id":75,"date":"2022-02-14T06:31:35","date_gmt":"2022-02-14T06:31:35","guid":{"rendered":"https:\/\/blog.wordgeeks.net\/?page_id=75"},"modified":"2023-05-15T03:59:00","modified_gmt":"2023-05-15T03:59:00","slug":"haskell-related","status":"publish","type":"page","link":"https:\/\/blog.wordgeeks.net\/?page_id=75","title":{"rendered":"Haskell related"},"content":{"rendered":"\n<p>As much as Haskell is fun to play with, its unique characteristics can make reasoning about its behaviors and debugging a daunting task. So here I&#8217;ll document everything I encountered, big and small.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"running-time-doesn-t-scale-with-input-size\">Running time doesn&#8217;t scale with input size<\/h3>\n\n\n\n<p>I have some code snippet like:<\/p>\n\n\n\n<div class=\"wp-block-urvanov-syntax-highlighter-code-block\"><pre class=\"lang:haskell decode:true \" >minIndex :: [a] -&gt; Int\nminIndex ls =\n  let\n    vals = map calc ls -- calc is some computation intensive function\n    (_, ret) = minimum $ zip vals [0..]\n  in ret<\/pre><\/div>\n\n\n\n<ul class=\"wp-block-list\">\n<li>When the list is of size 1, we get the result immediately.<\/li>\n\n\n\n<li>However, when the size is 2, it takes a long while before we get the result.<\/li>\n\n\n\n<li>For some other small size like 5 or 10, the time is proportional to that of size 2.<\/li>\n<\/ul>\n\n\n\n<p>Answer: because of the laziness, we don&#8217;t ever compare the result of <code>calc<\/code> in case of one element.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id=\"overflowed-spark\">Overflowed Spark<\/h3>\n\n\n\n<p>If we get too many sparks, those after the pool overflow will be calculated by the main thread. So with a large list, <code>parMap<\/code> isn&#8217;t going to work, and we need manual partition. And the behavior can seem like imbalanced input.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>As much as Haskell is fun to play with, its unique characteristics can make reasoning about its behaviors and debugging a daunting task. So here I&#8217;ll document everything I encountered, big and small. Running time doesn&#8217;t scale with input size I have some code snippet like: Answer: because of the laziness, we don&#8217;t ever compare&hellip; <a class=\"more-link\" href=\"https:\/\/blog.wordgeeks.net\/?page_id=75\">Continue reading <span class=\"screen-reader-text\">Haskell related<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"parent":0,"menu_order":2,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-75","page","type-page","status-publish","hentry","entry"],"_links":{"self":[{"href":"https:\/\/blog.wordgeeks.net\/index.php?rest_route=\/wp\/v2\/pages\/75","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.wordgeeks.net\/index.php?rest_route=\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/blog.wordgeeks.net\/index.php?rest_route=\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/blog.wordgeeks.net\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.wordgeeks.net\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=75"}],"version-history":[{"count":7,"href":"https:\/\/blog.wordgeeks.net\/index.php?rest_route=\/wp\/v2\/pages\/75\/revisions"}],"predecessor-version":[{"id":161,"href":"https:\/\/blog.wordgeeks.net\/index.php?rest_route=\/wp\/v2\/pages\/75\/revisions\/161"}],"wp:attachment":[{"href":"https:\/\/blog.wordgeeks.net\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=75"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}