{"id":168,"date":"2011-10-22T20:47:23","date_gmt":"2011-10-23T03:47:23","guid":{"rendered":"http:\/\/www.venzon.org\/?p=168"},"modified":"2011-10-22T20:49:05","modified_gmt":"2011-10-23T03:49:05","slug":"fun-with-haskell","status":"publish","type":"post","link":"http:\/\/www.venzon.org\/?p=168","title":{"rendered":"Fun with Haskell"},"content":{"rendered":"<p>Haskell is a great programming language and I have a lot of fun programming in it. I&#8217;ve been working fiddling around with a simple prototype for a board-game style game (more details on that later) and was figuring out how to draw a line connecting some positions on the game board. Specifically, I needed to figure out how to go from a calculated path to a list of line segments to draw. So, turning a list like this, where each element is a coordinate pair:<br \/>\n<code>[(1,1), (2,3), (4,4)]<\/code><br \/>\nInto a list like this, where each element is a line start\/end pair:<br \/>\n<code>[((1,1),(2,3)), ((2,3),(4,4))]<\/code><br \/>\nThis is a super easy problem to solve in any imperative language, just iterate through the elements making a connecting list, but Haskell is fun because you get to come up with awesome one-line solutions that don&#8217;t have any iteration:<\/p>\n<p><code>zip x (tail x)<\/code><\/p>\n<p>where x is your list. Done. Hooray!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Haskell is a great programming language and I have a lot of fun programming in it. I&#8217;ve been working fiddling around with a simple prototype for a board-game style game (more details on that later) and was figuring out how to draw a line connecting some positions on the game board. Specifically, I needed to [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[13,6],"tags":[],"class_list":["post-168","post","type-post","status-publish","format-standard","hentry","category-haskell","category-prototyping"],"_links":{"self":[{"href":"http:\/\/www.venzon.org\/index.php?rest_route=\/wp\/v2\/posts\/168","targetHints":{"allow":["GET"]}}],"collection":[{"href":"http:\/\/www.venzon.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"http:\/\/www.venzon.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"http:\/\/www.venzon.org\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"http:\/\/www.venzon.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=168"}],"version-history":[{"count":8,"href":"http:\/\/www.venzon.org\/index.php?rest_route=\/wp\/v2\/posts\/168\/revisions"}],"predecessor-version":[{"id":175,"href":"http:\/\/www.venzon.org\/index.php?rest_route=\/wp\/v2\/posts\/168\/revisions\/175"}],"wp:attachment":[{"href":"http:\/\/www.venzon.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=168"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"http:\/\/www.venzon.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=168"},{"taxonomy":"post_tag","embeddable":true,"href":"http:\/\/www.venzon.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=168"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}