tag:blogger.com,1999:blog-8643857899806162280.post6266337647952433957..comments2024-10-01T04:01:22.473-03:00Comments on Bug squash: Translating Haskell to F# and other considerationsMauricio Schefferhttp://www.blogger.com/profile/15247972578064164206noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-8643857899806162280.post-24051603247813920212010-01-11T12:01:08.061-03:002010-01-11T12:01:08.061-03:00Yes, that's exactly the library whose implemen...Yes, that's exactly the library whose implementation I linked to. :)<br /><br />Be aware that HT is not a standard Haskell library though.GMhttps://www.blogger.com/profile/07637024036051297719noreply@blogger.comtag:blogger.com,1999:blog-8643857899806162280.post-62755018243812864992010-01-11T11:42:15.494-03:002010-01-11T11:42:15.494-03:00@Anonymous, Greg: there's an even sweeter solu...@Anonymous, Greg: there's an even sweeter solution at <a href="http://www.reddit.com/r/haskell/comments/ancov/translating_haskell_to_f_and_other_considerations/" rel="nofollow">reddit</a>Mauricio Schefferhttps://www.blogger.com/profile/15247972578064164206noreply@blogger.comtag:blogger.com,1999:blog-8643857899806162280.post-56948933251168925022010-01-10T19:17:51.308-03:002010-01-10T19:17:51.308-03:00The archetypal Haskell solution looks like this:
...The archetypal Haskell solution looks like this:<br /><br />import Data.List (groupBy)<br /><br />gs = map (map snd) . groupBy (\(x1,y1) (x2,y2)->x1-x2==y1-y2) . zip [1..]<br />xs = [1,2,3,5,6,8,9]<br />main = print $ gs xsAnonymousnoreply@blogger.comtag:blogger.com,1999:blog-8643857899806162280.post-76480173879693552862010-01-09T19:25:54.473-03:002010-01-09T19:25:54.473-03:00Thanks for your comments Greg, Matías! I'm sti...Thanks for your comments Greg, Matías! I'm still a bit inexperienced in FP in general, and a total newbie in Haskell. I just copied here the first solution I found. However, it was not the point of the article to come up with the most efficient solution for this concrete problem, but rather to show some common pitfalls when translating Haskell to F# and doing recursion over lists in F#.Mauricio Schefferhttps://www.blogger.com/profile/15247972578064164206noreply@blogger.comtag:blogger.com,1999:blog-8643857899806162280.post-46511497160206777772010-01-09T10:14:39.837-03:002010-01-09T10:14:39.837-03:00This problem cries for a control break to solve it...This problem cries for a control break to solve it. I've written about this technique to solve an essentially equivalent problem in OCaml <a href="http://alaska-kamtchatka.blogspot.com/2008/10/extreme-recursion.html" rel="nofollow">here</a> and <a href="http://alaska-kamtchatka.blogspot.com/2008/10/group-by-redux.html" rel="nofollow">here</a>.Matías Giovanninihttps://www.blogger.com/profile/17772004856076119446noreply@blogger.comtag:blogger.com,1999:blog-8643857899806162280.post-77302802102865160492010-01-09T02:38:35.746-03:002010-01-09T02:38:35.746-03:00I don't like the look of that haskell code. It...I don't like the look of that haskell code. It certainly could be simpler, and the complexity makes it hard to be sure it's efficient (and I presume it's not because init, last and multiple ++s rarely are).<br /><br />Presumably <a href="http://hackage.haskell.org/packages/archive/utility-ht/0.0.5.1/doc/html/src/Data-List-Key-Private.html" rel="nofollow">this</a> is the correct and efficient way to do it, but it's more general and less explicit so let me write a version closer to the one you started with (how do I format this? sorry):<br /><br /><br />groupConsec [] = []<br />groupConsec [a] = [[a]]<br />groupConsec (a:b:cs) | a+1==b = (a:xs):xss<br /> | otherwise = [a] : xs : xss<br /> where (xs:xss) = groupConsec (b:cs)GMhttps://www.blogger.com/profile/07637024036051297719noreply@blogger.com