tag:blogger.com,1999:blog-21500237.post5773124163893370921..comments2023-04-29T04:08:32.247-04:00Comments on Praise, Curse, and Recurse: The Dot-Matrix Printhead: a Haskell ToyPaul R. Pottshttp://www.blogger.com/profile/04401509483200614806noreply@blogger.comBlogger6125tag:blogger.com,1999:blog-21500237.post-30785358899892566742006-12-16T08:11:00.000-05:002006-12-16T08:11:00.000-05:00Also, folding a [Bool] into a successively concate...Also, folding a [Bool] into a successively concatenated String doesn't seem ideal. Since String is equivalent to [Char], you could map each Bool directly to its equivalent Char:<br /><br />$ ghci<br />Prelude> let stringify_vals = map (\x -> if x then '#' else ' ')<br />Prelude> stringify_vals [False, False, True, False]<br />" # "<br /><br />If, however, your purpose was to demonstrate fold, then the version given is OK.<br /><br />Also also, I'm pretty sure most of the _rot functions aren't strictly necessary. You should be able to transpose the [String] right before unlines-ing it. So you would only need the two prettyprint_blah_rot functions.<br /><br />Also also also, I tried saving the body text as a .lhs, but GHCi choked on lines that started with '#'. <br /><br />Also x 4 (*sigh*), short names are a matter of taste. I wouldn't dare discourage using more descriptive names!<br /><br />Anyway, happy Haskelling!Unknownhttps://www.blogger.com/profile/05423466002788031695noreply@blogger.comtag:blogger.com,1999:blog-21500237.post-9644587326748500282006-12-16T07:19:00.000-05:002006-12-16T07:19:00.000-05:00"Now we want a function to access the bits of thos..."Now we want a function to access the bits of those numbers from most <br />significant to least significant and build a list of corresponding <br />boolean values. This would be expressed more naturally if EnumFromTo<br />operated descending sequences."<br /><br />Doesn't Haskell support this? Lemme try:<br /><br />$ ghci<br />Prelude> [5..1]<br />[]<br /><br />Hmm. Oh yeah, you need to give it a hint:<br /><br />Prelude> [5,4..1]<br />[5,4,3,2,1]<br /><br />Yay!Unknownhttps://www.blogger.com/profile/05423466002788031695noreply@blogger.comtag:blogger.com,1999:blog-21500237.post-14710796266115021452006-12-13T12:33:00.000-05:002006-12-13T12:33:00.000-05:00These are great suggestions, thanks!
As to the q...These are great suggestions, thanks! <br /><br />As to the question of fold, I guess I was writing a lambda to illustrate the parallels of addition to my string accumulation, but certainly if I really wanted "+" I should just use the existing function.<br /><br />Short function names -- check. I have gotten used to writing quite long method names in C++ (for classes with a lot of methods). It has probably instilled habits that are not helpful in Haskell!<br /><br />Jason, I appreciate your rewrite... it is definitely improved.<br /><br />I will prepare a followup presenting an improved version.Paul R. Pottshttps://www.blogger.com/profile/04401509483200614806noreply@blogger.comtag:blogger.com,1999:blog-21500237.post-26694998847256708532006-12-13T10:49:00.000-05:002006-12-13T10:49:00.000-05:00umm... also... why write [n | numm... also... why write [n | n <- [a .. b]] when you can write [a .. b]?<br /><br />8-)<br /><br />and guards are helpful...<br /><br />Haskell syntax is like a box full of chocolates... *-)Imam Tashdid ul Alamhttps://www.blogger.com/profile/01603987396716404785noreply@blogger.comtag:blogger.com,1999:blog-21500237.post-27673198556916628472006-12-13T10:46:00.000-05:002006-12-13T10:46:00.000-05:00well, choosing short function names is "Haskellish...well, choosing short function names is "Haskellish", why? you know by now I guess...<br /><br />also, "Haskellers" would prefer <br />foldl (+) ...<br />over<br />foldl (\x y -> x + y) ...<br /><br />why? idunno 8-)Imam Tashdid ul Alamhttps://www.blogger.com/profile/01603987396716404785noreply@blogger.comtag:blogger.com,1999:blog-21500237.post-27889084878701213152006-12-12T23:16:00.000-05:002006-12-12T23:16:00.000-05:00I was going to post my attempt here, but since blo...I was going to post my attempt here, but since blogger helpfully disallows the pre tag in comments, I decided to <a href="http://jcreigh.blogspot.com/2006/12/fun-with-bitmaps.html">post it to my blog</a> instead.Jasonhttps://www.blogger.com/profile/03218766081192764530noreply@blogger.com