<?xml version='1.0' encoding='UTF-8'?><?xml-stylesheet href="http://www.blogger.com/styles/atom.css" type="text/css"?><feed xmlns='http://www.w3.org/2005/Atom' xmlns:openSearch='http://a9.com/-/spec/opensearchrss/1.0/' xmlns:georss='http://www.georss.org/georss' xmlns:gd='http://schemas.google.com/g/2005' xmlns:thr='http://purl.org/syndication/thread/1.0'><id>tag:blogger.com,1999:blog-2615156186192493130</id><updated>2011-10-28T21:22:47.308-07:00</updated><category term='C#'/><category term='bitterness'/><category term='bluetooth'/><category term='arrows'/><category term='oh crap that was dumb'/><category term='haskell'/><category term='security'/><category term='frp'/><category term='emo'/><category term='performance'/><category term='games'/><category term='matrioshka'/><category term='laziness'/><category term='epigram'/><title type='text'>Abstract Absurdities</title><subtitle type='html'></subtitle><link rel='http://schemas.google.com/g/2005#feed' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/posts/default'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default?max-results=100'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/'/><link rel='hub' href='http://pubsubhubbub.appspot.com/'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><generator version='7.00' uri='http://www.blogger.com'>Blogger</generator><openSearch:totalResults>28</openSearch:totalResults><openSearch:startIndex>1</openSearch:startIndex><openSearch:itemsPerPage>100</openSearch:itemsPerPage><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-4230599045792331010</id><published>2010-01-27T18:35:00.000-08:00</published><updated>2010-01-27T18:35:27.062-08:00</updated><title type='text'>Weight Loss:  When Hungry, Eat</title><content type='html'>I'm still plugging away at a number of technical topics, so I wanted to share a bit more of my experience with food and weight loss.&lt;br /&gt;&lt;br /&gt;There's a rule that I didn't mention last time, and it's possibly the most important of all of them: &amp;nbsp;when you're hungry, eat something. &amp;nbsp;I discovered that in order to keep losing weight over a long period, I couldn't starve myself. &amp;nbsp;I had to eat whenever I felt like my body needed food and I had to eat until I wasn't hungry. &amp;nbsp;Sometimes that's meant eating four or five small meals in a day. &lt;br /&gt;&lt;br /&gt;Eating when you're hungry is a little scary when you've had problems with your weight. &amp;nbsp;It's easier to have rigid rules for what and when you eat. &amp;nbsp;There is, and probably always will be, a little voice that's scared of putting it all back on again. &amp;nbsp;That's a reasonable concern, after all! &amp;nbsp;To deal with this voice, you simply have to listen carefully to your body's signals of what it needs and trust that countless ages of evolution have - in fact - provided you with the tools you need.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-4230599045792331010?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/4230599045792331010/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=4230599045792331010' title='35 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/4230599045792331010'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/4230599045792331010'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2010/01/weight-loss-when-hungry-eat.html' title='Weight Loss:  When Hungry, Eat'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>35</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-8720889117181882176</id><published>2010-01-18T14:34:00.001-08:00</published><updated>2010-01-18T14:34:00.126-08:00</updated><title type='text'>Weight Loss: My Success</title><content type='html'>&lt;div&gt;I've spent most of my post-teenage life struggling with my weight.  About 16 months ago, I made a fairly radical change to my eating habits and I've now lost 103 lbs.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;There's two major things I changed about my diet.  First, I ate less sugar.  Second, I ate slower.  Before I get into the details, I want to clarify something.  I am a vegetarian now, but that's a decision unrelated to my attempt to lose weight.  I lost &lt;b&gt;over&lt;/b&gt; &lt;b&gt;60 lbs&lt;/b&gt; before I became a vegetarian.  Vegetarianism wasn't a prerequisite.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Eat less sugar.  That sounds pretty simple, doesn't it?  Unfortunately, it was a lot harder than I thought it would be.  A lot of preprocessed foods, including most bread you'll find in the super market, include superfluous high-fructose corn syrup.  Even foods that market themselves as healthy will include copious amounts of sugar; they just cut out the fat instead.  Unfortunately, that's the opposite of what my experience has taught me.  &lt;i&gt;I choose fat over sugar&lt;/i&gt;.  My body can actually break down fat and do something useful it.  &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I found that once I reduced the amount of sugar I consumed drastically, my appetite became more regular and manageable.  I get hungry again quickly when I have sugary food and it's usually accompanied by headaches, not by an empty stomach.  I also have a harder time telling just how hungry I am when I've had much sugar.  It scrambles my sense of what I need.  I'm really vigilant now to check the labels of food I buy in the store.  I also cook more of my own meals than I used to.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Fresh fruit is my one exception to the above rule.  Fruit doesn't cause me any of the problems that, say, corn syrup laden bread does.  I don't entirely understand why, but it seems to be broken down differently.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Eating slow was the other key change to my life style.  If I wolf down my food, I can very easily eat more than I actually need without realizing it.  I discovered that if I just slow down, take breaks, and take the radical step of &lt;i&gt;chewing&lt;/i&gt; that I can actually tell when I've had enough food.  I was never aware of the whole spectrum of sensations in my stomach until I slowed down and paid attention.  I was amazed to discover that there's more than just "starving" and "stuffed".&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Just these two things, I think, were the most important parts of my experience losing weight.  &lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-8720889117181882176?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/8720889117181882176/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=8720889117181882176' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/8720889117181882176'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/8720889117181882176'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2010/01/weight-loss-my-success.html' title='Weight Loss: My Success'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-7742885174345324752</id><published>2009-10-10T17:06:00.003-07:00</published><updated>2009-10-10T18:05:50.972-07:00</updated><title type='text'>How to teach Category Theory?</title><content type='html'>So I'm teaching an intro to category theory course this fall at Portland State, my new place of employment.  &lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Now, I think it's going alright.  I have only 6 people in on this class, including one professor, but I imagine that if I teach it again in the future and advertise it a bit harder that there will be more.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;It's been an interesting experience, though, because I've realized one of the big problems with trying to explain category theory:  it's too young a field.  We have all the definitions, but none of the metaphors.  There's no coherent narrative to give you intuition.  "Categories for the Working Mathematician", one of my all time favorite books, cheats pretty seriously on this front.  It never gives a basic vocabulary to use to &lt;i&gt;describe&lt;/i&gt; any of these structures, it just gives so many examples from other areas of math that you start to build an intuition; however, you have almost no words with which to explain this intuition.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I was inspired to write more about this because of a thread on &lt;a href="http://www.reddit.com/r/haskell/comments/9ski4/a_more_approachable_approach_to_category_theory/"&gt;reddit&lt;/a&gt;.  I strongly disagree with the sentiment that one should be able to explain the concepts of category theory in terms of functional programming.  Some ideas in category theory- such as representable functors, adjoints, hom-sets, topoi - are general enough that any attempts to squash them into Haskell code is simplifying to the point of confusion.  An example of this is Dan Piponi's old post on the &lt;a href="http://blog.sigfpe.com/2006/11/yoneda-lemma.html"&gt;Yoneda lemma&lt;/a&gt;.  While it's good and gives intuition, it's also a bit of a lie- the Haskell arrow (-&gt;) is not actually a hom-set and Yoneda is all about the relation between hom-sets and natural transformations that allows you to embed any category C into the category of functors from C to Set, a category with much richer logical structure.  As much as the analogy to Haskell helps, I think it hurts by making the big, general, picture harder to see.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So is the solution to suck it up and just bang your head against Mac Lane, never thinking about how it relates to code?  Of course not!  Let's take a slight detour, first, before talking about what to do.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So Paul Graham has this famous essay - famous enough I don't even see a point to linking it - about "Blub programmers" and how they're blind to the powers of better tools because they only know Blub.  It probably wasn't Graham's intent, but this essay is usually referenced by language evangelists to explain why some programmer they talk to isn't instantly willing to adopt their favorite language despite how awesome it is.  It's a seductive explanation.  The people who disagree with them don't "get it" or just aren't trying.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The more likely reason?  They're terrible at explaining why their language is good.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;When I was a grad student in physics, most of the grad students (myself included, much to my shame) joked about how dumb all the pre-med students were and how they never wanted to do any work, because that was the most convenient explanation for why there were so many complaints about how hard &amp;amp; confusing the labs, lectures, etc. were.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The more likely reason?  We were terrible at explaining physics.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;That brings me back to the course I'm teaching.  I'm spending the majority of my time trying to figure out real metaphors for explaining category theory, especially with respect to its uses in Computer Science.  &lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;So far, the basic story I'm going with is that category theory is about "modeling structures".  Functors are about instances of models in a target category.  Natural transformations are ways to move between two models in a "coherent" fashion.  I'm still fleshing out this language, and I don't know how terribly helpful it will be at the end of the day, but I'll be cleaning up and releasing my notes at the end of the term as one long pdf.  The point is that there's still a lot of programmers, computer scientists, and even mathematicians that don't see category theory for the beautiful foundational math I see.  Now, it's possible that they're all stupid or don't want to work.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;The more likely reason?&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-7742885174345324752?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/7742885174345324752/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=7742885174345324752' title='19 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/7742885174345324752'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/7742885174345324752'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2009/10/how-to-teach-category-theory.html' title='How to teach Category Theory?'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>19</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-5609526844839170716</id><published>2009-01-24T21:33:00.004-08:00</published><updated>2009-01-24T21:57:54.000-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><category scheme='http://www.blogger.com/atom/ns#' term='oh crap that was dumb'/><category scheme='http://www.blogger.com/atom/ns#' term='emo'/><title type='text'>Fear of releasing code</title><content type='html'>Alright, so this post is going to be all Captain Emo.  I wanted to write about something I've realized I do, with the hope that if someone else is unfortunate enough to have the same habit that maybe they'll realize it as well.&lt;br /&gt;&lt;br /&gt;I sometimes have a ridiculously irrational fear of actually finishing up &amp;amp; releasing my personal projects.&lt;br /&gt;&lt;br /&gt;Of course, it doesn't manifest itself as transparently as "oh, crap, people might see my code &amp;amp; think I punch puppies".  It's much more of a "gosh, I just don't know if it's really tested enough yet" or "why don't I add a few more features first" or "I'll just tweak the API a bit" or even the insidious "I'll work on that tomorrow".  Oh yes, "tomorrow" being that wonderful code word for "maybe around the time I start laying golden eggs".  Sometimes I've even thrown out a good chunk of work I had finished because I thought of a "better way" which mysteriously never gets coded up.&lt;br /&gt;&lt;br /&gt;Here's the important point I've been thinking about:  something is only perfect if it doesn't exist.  If you want to actually accomplish anything, you're going to release stuff that is buggy, non-optimal, &amp;amp; might not even compile on anyone else's machine.  That's okay.  It can get fixed! &lt;br /&gt;&lt;br /&gt;I've never lost respect for someone because of a bug in a library.  I've only gained respect for them when they fix it.  I'm probably not the only one who feels that way.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-5609526844839170716?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/5609526844839170716/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=5609526844839170716' title='8 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/5609526844839170716'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/5609526844839170716'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2009/01/fear-of-releasing-code.html' title='Fear of releasing code'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>8</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-1843498126813558115</id><published>2008-10-30T05:05:00.004-07:00</published><updated>2008-10-30T05:24:16.549-07:00</updated><title type='text'>An almost religious experience</title><content type='html'>Alright, so this is a bit off topic for this blog but I had to talk about something that amazed and astounded me.&lt;br /&gt;&lt;br /&gt;Last night, after the Obammercial, I was flipping through the channels and I came across a sitcom called "Under One Roof" starring, not joking, Flavor Flav and a cast of people designed to make Mr. Flav not look like the craziest person on the set. &lt;br /&gt;&lt;br /&gt;This show was so strange &amp;amp; surreal that at any minute I expected the real credits to roll and for it to be some extended sketch of another comedy show.  For God's sake, it actually featured a wacky-Asian-stereotype cook who uttered the phrase "me so horny".  The strange gesticulations, the bizarre dialog, the constant mugging &amp;amp; posturing for the camera all made it impossible for the brain to accept that it was watching something non-ironically meant for entertainment.  Yet sure enough the credits rolled after a half-hour.&lt;br /&gt;&lt;br /&gt;Then it hit me.&lt;br /&gt;&lt;br /&gt;I had just witnessed the first Dadaist Sitcom.  This wasn't just not funny, it was true anti-art.  It wasn't that the show failed at entertaining.  It succeeded at destroying the very concepts of entertainment &amp;amp; humor, leaving only a void.  A void that challenged my fundamental assumptions about the place of entertainment in society.  It made me question not why this show existed but why no other could be so profound and challenging.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-1843498126813558115?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/1843498126813558115/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=1843498126813558115' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/1843498126813558115'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/1843498126813558115'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2008/10/almost-religious-experience.html' title='An almost religious experience'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-3431062716464873027</id><published>2008-10-28T15:15:00.001-07:00</published><updated>2008-10-28T15:16:41.239-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='games'/><category scheme='http://www.blogger.com/atom/ns#' term='bluetooth'/><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><category scheme='http://www.blogger.com/atom/ns#' term='oh crap that was dumb'/><title type='text'>Debugging &amp; Refactoring, a mid-mortum</title><content type='html'>So I haven't touched my Bluetooth bindings in the past week, having been a bit intimidated by the prospect of sitting down and making the necessary network interfaces to actually handle doing real communication &amp;amp; not just simple queries.  I can tell it's not going to be too hard once I get started, but it doesn't look like the most exciting thing in the world.&lt;br /&gt;&lt;br /&gt;To get my motivation up, I worked instead on some of the small physics games into which I wanted to eventually integrate wiimote controls.  Making a small game engine in Haskell hasn't been entirely easy, but that's more a function of my inexperience &amp;amp; that I don't think I've been using language features to their best advantage. &lt;br /&gt;&lt;br /&gt;I lost a bit of my time wrestling with trying to make the engine interface feel "object oriented", which is where my mini-rant about type class abuse last week came from.&lt;br /&gt;&lt;br /&gt;At this point, though, I have a good percentage of the code I need to make a few of my game ideas; however, the percentage of code that's working in all the cases it needs to is much smaller, particularly the generic collision detection &amp;amp; handling for polygons.  There's a number of cases in my testing that keep coming up with unexpected results.&lt;br /&gt;&lt;br /&gt;I've spent some time in the GHCi debugger, which is actually a lot more easy to use than I expected.  If you haven't used the debugger yet I recommend that you read &lt;a href="http://www.haskell.org/sitewiki/images/0/0a/TMR-Issue10.pdf"&gt;issue 10&lt;/a&gt; of The Monad Reader and the rather nice tutorial provided therein.  One minor thing I want to emphasize about using the debugger is that if you force a value that's returned by a function before you start stepping through the function, you won't actually step through the function by doing :step.  GHCi will just continue with whatever compuation is done with the value you forced.  Again, it's a minor thing but it took me a few seconds to realize why I skipped over the step-thru of one of the functions I was trying to diagnose.&lt;br /&gt;&lt;br /&gt;Even though the debugger is actually fairly nice, my real problem is that I've made a number of small logical mistakes &amp;amp; built upon those mistakes without realizing I had made them in the first place.  I think a good next step for this project would be to start pulling in the old QuickCheck machinery, trying to define the algebraic properties the functions in the physics engine should obey, refactoring the whole mess, and making sure it passes all of my tests from the get-go.  This should prevent the "Oh, I think everything is fixed now so let's just start bouncing some squares around the screen...looks good...great...@#%*!" loop.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-3431062716464873027?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/3431062716464873027/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=3431062716464873027' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/3431062716464873027'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/3431062716464873027'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2008/10/debugging-refactoring-mid-mortum.html' title='Debugging &amp; Refactoring, a mid-mortum'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-1685575108228586585</id><published>2008-10-27T15:00:00.002-07:00</published><updated>2008-10-27T15:00:00.844-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='matrioshka'/><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><category scheme='http://www.blogger.com/atom/ns#' term='security'/><title type='text'>More on OS design</title><content type='html'>I've been thinking a bit again about modern type systems with respect to operating system design and I think I can describe heuristically some of my old ideas and the open questions I still have.  If there are comments or ideas, I'd love to hear them.&lt;br /&gt;&lt;br /&gt;I like modern type systems.  I also like capabilities.  How can we combine them together?  I used to think I had more solid leads on this question, but now I feel a little shaky.  What I wanted to do was have a set of capabilities, essentially just indexes into some resource mapping in the kernel, be attached to each process.  The actual access rights for each resource would be encoded as a phantom type in the capability.  So for each resource type you'd have some set of operations that would have preconditions about the phantom types they would find acceptable.  If you wanted to pass a capability to another process you can use provided functions for making a copy securely, giving any level of permissions less than or equivalent to your own.&lt;br /&gt;&lt;br /&gt;Now there are some things that I think make sense here:  the more we can shove questions of safety into the type system, the less we have to do at runtime and the better scalability you can have.  Also, I think it encourages a very different UI experience.  To see a resource you need to have a capability to it, but if you're dispatching over the type of capability then presumably you could do something like have the only shell commands available for that resource be the ones that match the type signature of the resource.  I'm not sure how to actually implement a feature like that, but it seems like it should be feasible on a moral level.&lt;br /&gt;&lt;br /&gt;I feel like there's three questions I have to answer in order to take the idea from "oh that's kinda cute" to something real.  The first problem is bootstrapping and snapshotting of the OS.  I haven't even begun to think about this, honestly.&lt;br /&gt;&lt;br /&gt;Another issue is how the process and system call model would have to work.  We'd want the system calls to be somehow typechecked for proper capability use.  Again, I'm not sure of a good scheme for this that doesn't restrict execution to just the host language.  Perhaps the bullet that has to be bitten involves making some form of FFI for each compiler that should target this system so that the system calls are made in the host language and then type checked at compilation.&lt;br /&gt;&lt;br /&gt;The last issue that's still fuzzy in my head involves storing capabilities for a process.  Now, it's all fine and dandy to say 'it's a set', but most data structures in a language such as Haskell are homogenous.  What I need is a heterogenous container that doesn't completly lose type information, which means that using type classes and existentials is right out.  I know Oleg Kiselyov has done work with thing like HList, but that's something I don't know much about.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-1685575108228586585?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/1685575108228586585/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=1685575108228586585' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/1685575108228586585'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/1685575108228586585'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2008/10/more-on-os-design.html' title='More on OS design'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-2614410641527890133</id><published>2008-10-23T15:00:00.001-07:00</published><updated>2008-10-23T15:00:00.868-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><category scheme='http://www.blogger.com/atom/ns#' term='security'/><title type='text'>Revisiting old concepts</title><content type='html'>In an &lt;a href="http://abstractabsurd.blogspot.com/2007/06/exokernels-typeclasses.html"&gt;old post&lt;/a&gt; I threw out the perspective that typeclasses &amp;amp; exokernels are similar ideas, but I explained it so pithily I think it was more or less incomprehensible.  Honestly, even I had to sit &amp;amp; think for a minute to figure out what I meant over a year ago.&lt;br /&gt;&lt;br /&gt;The idea wasn't really that profound, but did amuse me a little.&lt;br /&gt;&lt;br /&gt;Let's say that you design a type class called Hardware, maybe even require that it be a monad or at least applicative, that includes all of the functionality you'd want from an exokernel, i.e. protection &amp;amp; raw handling of resources.  You should also define a set of algebraic properties that you want all of these operations to satisfy in practice.&lt;br /&gt;&lt;br /&gt;Any actual instance of this type class that satisfies all of our conditions is an implementation of an exokernel.&lt;br /&gt;&lt;br /&gt;Then your libOS, the part that does all the nasty work of management of resources, can be polymorphic over the implementation and only work with the basic protection interface defined by the type class.&lt;br /&gt;&lt;br /&gt;This whole business occurred to me a long time ago because of reading the original House paper and their discussion of the H monad.  They don't quite take it in this direction, but I think that it seems feasible.&lt;br /&gt;&lt;br /&gt;I'm being a little hand-wavy, though, because this isn't something I've&lt;br /&gt;actually tried to make.  It just seems like a compelling bit of imagery &amp;amp; possibly a good idea for organizing a kernel.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-2614410641527890133?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/2614410641527890133/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=2614410641527890133' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/2614410641527890133'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/2614410641527890133'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2008/10/revisiting-old-concepts.html' title='Revisiting old concepts'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-6146768318794104427</id><published>2008-10-22T11:50:00.000-07:00</published><updated>2008-10-22T11:51:10.993-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><category scheme='http://www.blogger.com/atom/ns#' term='oh crap that was dumb'/><title type='text'>A serious problem</title><content type='html'>Hello,&lt;br /&gt;I'm Creighton Hogg and I want to talk to you about typeclass abuse. &lt;br /&gt;&lt;br /&gt;Like any form of substance abuse it may seem harmless at first, a way  &lt;br /&gt;to recapture the old feelings of modularity you had during your&lt;br /&gt;object-oriented youth; however, you'll quickly find yourself twisting&lt;br /&gt;and obfuscating your code to design the signatures of your typeclass&lt;br /&gt;methods so that they can cover a wide swath of cases that are&lt;br /&gt;fundamentally dissimilar.&lt;br /&gt;&lt;br /&gt;Have you noticed signs of:&lt;br /&gt;    1.  Obsession over reuse of the names of functions?&lt;br /&gt;    2.  Attempts to use typeclasses to try and treat collections of&lt;br /&gt;        dissimilar objects as though they were the same?&lt;br /&gt;    3.  A frequent need for typeclasses with two or more type&lt;br /&gt;        variables?  &lt;br /&gt;&lt;br /&gt;If so, you may be in grips of typeclass abuse.  Please keep the&lt;br /&gt;following in mind as you attempt to deal with your problem.&lt;br /&gt;&lt;br /&gt;First, if you want to have a collection of objects that are treated&lt;br /&gt;differently by functions, please consider using an Algebraic Data Type&lt;br /&gt;instead.  For more fine grained control over your data types, you may&lt;br /&gt;want to look into GADTs.&lt;br /&gt;&lt;br /&gt;Second, if you are needing a number of classes with two or more type&lt;br /&gt;variables, consider that you may be attempting to use a language feature&lt;br /&gt;designed to enable polymorphism to handle extremely specific and&lt;br /&gt;dissimilar cases.  You are working against the grain of the language,&lt;br /&gt;and should probably simply accept that you can't overload a function&lt;br /&gt;name to be 20 different functions that each do different things.&lt;br /&gt;&lt;br /&gt;Lastly, if you're not actually sure if a typeclass would make your code&lt;br /&gt;more convenient, why not just try writing your code without it?  When&lt;br /&gt;you've got a number of use cases down, then maybe you can decide on what&lt;br /&gt;the proper abstraction is.&lt;br /&gt;&lt;br /&gt;This message paid for by the Foundation To Get Creighton To Stop Abusing&lt;br /&gt;His Code, a non-profit organization.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-6146768318794104427?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/6146768318794104427/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=6146768318794104427' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/6146768318794104427'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/6146768318794104427'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2008/10/serious-problem.html' title='A serious problem'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-1020436154953313015</id><published>2008-10-13T16:13:00.002-07:00</published><updated>2008-10-13T16:23:04.359-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><category scheme='http://www.blogger.com/atom/ns#' term='bitterness'/><title type='text'>Brief updates</title><content type='html'>So two quick notes:&lt;br /&gt;&lt;ol&gt;&lt;li&gt;I've been working on my Haskell bindings to BlueZ and I can now detect my wiimote.  I can't read anything from it or tell it to do anything, but I know it's there.  I'm hoping to have some kind of actual release done next week.&lt;/li&gt;&lt;li&gt;Any political candidate who starts talking about how "great" our country is should be poked in the eyes, 3 Stooges style.  We know you like the place or you wouldn't be running for office and if you keep talking about how great things are you look like you don't have ideas to make it better.  Seriously.&lt;br /&gt;&lt;/li&gt;&lt;/ol&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-1020436154953313015?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/1020436154953313015/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=1020436154953313015' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/1020436154953313015'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/1020436154953313015'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2008/10/brief-updates.html' title='Brief updates'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-4028566926491456544</id><published>2008-10-13T09:08:00.002-07:00</published><updated>2008-10-13T09:11:17.365-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><title type='text'>A silly example and a brief history</title><content type='html'>So there's a few things I've thought about lately, and I wanted to bring back one of the first things I ever wrote in Haskell as a launch point.&lt;br /&gt;&lt;br /&gt;I think I've made reference to this a few times, but in grad school I worked in experimental particle physics.  I left with a Master's after three years when I realized that the field just wasn't going to be right for me.  It was in particle physics that I got my first introduction to programming.  I was exposed to C++ and Fortran 77 as my first languages.  The funny thing is that back then I thought that programming was something difficult and scary, far more so than QFT or category theory.  &lt;br /&gt;&lt;br /&gt;I was utterly dumbfounded when I tried to read the source code of Pythia, the biggest event generator we used, and waded through the tens of thousands of lines of Fortran 77.  I came away with the impression that even basic concepts such as Monte Carlo integration were far too difficult for me to understand.  After working on a small emulator for detector logic in C++, my first real software project, I started to feel more comfortable with the idea that I &lt;em&gt;could&lt;/em&gt; actually understand the Crazy Witchcraft that is programming.  I also started wondering if there were other tools out there that were better than C++.&lt;br /&gt;&lt;br /&gt;The first language that really intrigued me was Ruby, but while working through the Pickaxe book I then started wondering if it was possible to go beyond Ruby's blocks and start really passing functions to other functions.  After spending a little time on The Google, I came across both Common Lisp and Haskell.  Haskell seemed really neat, but was rather strange for someone who was entirely self-taught in &lt;em&gt;Fortran&lt;/em&gt; and &lt;em&gt;C++&lt;/em&gt;.  One of the first semi-interesting code snippets I wrote in Haskell was the classic example of estimating pi Monte Carlo style.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;&gt; import System.Random&lt;br /&gt;&gt; import Control.Monad&lt;br /&gt;&gt; import System.Environment&lt;br /&gt;&gt;&lt;br /&gt;&gt; main' = do&lt;br /&gt;&gt;   [n] &lt;- getArgs&lt;br /&gt;&gt;   let n' = read n &lt;br /&gt;&gt;   ps &lt;- replicateM n' generatePoint&lt;br /&gt;&gt;   print $ 4 * (fromIntegral . length . filter (\(x,y) -&gt; x^2 + y^2 &lt;= 1)) ps / (fromIntegral n')&lt;br /&gt;&gt;&lt;br /&gt;&gt; generatePoint :: IO (Double,Double)&lt;br /&gt;&gt; generatePoint = do&lt;br /&gt;&gt;   x &lt;- randomRIO (-1,1)&lt;br /&gt;&gt;   y &lt;- randomRIO (-1,1)&lt;br /&gt;&gt;   return (x,y)&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now, I'm not saying that this code was &lt;em&gt;good&lt;/em&gt;, and I know I could do a lot better, but it does run and it was the first time I looked at code I had written and said &lt;q&gt;oh, I guess that wasn't so hard&lt;/q&gt;.  It had actually been really straight forward, far more straight forward to me than Fortran.  It made more sense.&lt;br /&gt;&lt;br /&gt;It felt more like math.  Math makes sense to me.  Abstract algebra, category theory, etc. feel comforting to my brain.  &lt;br /&gt;&lt;br /&gt;In the almost two years since I left grad school, I've done spurts of programming and studying CS and math.  Until recently, I had pulled a bit of a Joel Reymont and switched which tools I used for projects on an all too frequent basis.  For the past couple of months, I've really settled down on Haskell as my tool of choice.  Why?  Because it's the most math like programming language I've used.  It makes more sense.  It encourages abstraction in the math sense.&lt;br /&gt;&lt;br /&gt;Huh?  What's that supposed to mean?  &lt;br /&gt;&lt;br /&gt;Look at abstractions such as Functors, Monads, Applicative Functors, Arrows, etc.  In programming, abstraction is normally about not having to repeat yourself or about making code more modular.  Sure, the Monad typeclass does both of those things but it also encodes much more.  It encodes algebraic information about programs, about how our programs behave under transformation and calculation.  That's mathematical abstraction:  reducing your problem to structures that are as general as possible, using only the most basic rules that you need to accomplish your &lt;q&gt;proof&lt;/q&gt;.&lt;br /&gt;&lt;br /&gt;So that's kind of my history and current thoughts on programming.  I'm still learning a lot right now, but it's a lot more fun than I'd ever thought it'd be back when I was still in grad school.  Haskell has proved to be a rather enjoyable intersection point between the pragmatic and the mathematic.&lt;br /&gt;&lt;br /&gt;...at least until Epigram 2 is done.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-4028566926491456544?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/4028566926491456544/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=4028566926491456544' title='25 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/4028566926491456544'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/4028566926491456544'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2008/10/silly-example-and-brief-history.html' title='A silly example and a brief history'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>25</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-7895886698467133271</id><published>2008-10-07T17:41:00.005-07:00</published><updated>2008-10-08T05:14:35.112-07:00</updated><title type='text'>Working through Genetic Programming</title><content type='html'>&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;&gt; import Random&lt;br /&gt;&gt; import Control.Monad&lt;br /&gt;&gt; import Control.Monad.Random&lt;br /&gt;&gt; import Data.Ratio&lt;br /&gt;&gt; import Data.List (sortBy)&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;So I really did accomplish my reading of the first three chapters of Koza's first book on Genetic Programming the week I said I would, but I sat on this post for a good bit afterwards.   There wasn't a lot of meat in those initial chapters except for a few salient points:&lt;br /&gt;&lt;ol&gt;&lt;br /&gt;&lt;li&gt; Genetic programming can give you good answer if you're willing to accept that the answer is not 'correct', merely accurate and if you're willing to lay aside preconceived notions of beauty in your solutions.&lt;br /&gt;&lt;li&gt; Due to the schema theorem, a genetic recombination/fitness based search can effectively cover a large swath of the solution space with a small population.&lt;br /&gt;&lt;/ol&gt;&lt;br /&gt;The majority of Ch. 3 of the book is devoted to Old School genetic algorithms and the schema theorem.  I'm not going to bother going through fully fledged examples of the schema theorem, but I think the point can be understood fairly intuitively:  when you proportionally select the fittest specimen to be in the mating pool of each generation, you are making judgements about the fitness of patterns of genes and thus gather information about not just the specimen you have but all the possible specimen that have overlapping genetic structure.&lt;br /&gt;&lt;br /&gt;What I want to do in the rest of this post is just write my own tiny, not terribly well-featured, genetic algorithm implementation.  I'm hoping that this will provide not only more practice for me, but also be instructive to others.  I base the implementation more upon the heuristic description that Koza gives than on anything else and make no claim that this is any kind of optimal construction.&lt;br /&gt;&lt;br /&gt;First, since I hope to express my code at least somewhat generically between genetic algorithms and genetic programs, I'm going to define a typeclass to capture the basic behavior required of a "genetic" structure.  Also, it is worth noting that in this post I'm going to make gratuitious use of the Control.Monad.Random library just because it feels somehow appropriate to be doing these calculations in a monad.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;&gt; class Genome a where&lt;br /&gt;&gt;     mutation :: MonadRandom m =&gt; a -&gt; m a&lt;br /&gt;&gt;     recombination :: MonadRandom m =&gt; a -&gt; a -&gt; m (a,a)&lt;br /&gt;&gt;&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Oddly enough, that didn't seem too terrible.  We have no notion of how &lt;em&gt;often&lt;/em&gt; something like mutation in the typeclass, because that should be controlled at the level of the actual implementation.&lt;br /&gt;&lt;br /&gt;Now, though, we'll define an instance of this class for lists as that's probably the easiest thing to do.  I do, however, make the implicit assumption that in a given simulation all the specimen are of the same length. &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;&gt; &lt;br /&gt;&gt; instance Random a =&gt; Genome [a] where&lt;br /&gt;&gt;     mutation xs = do&lt;br /&gt;&gt;                   i &lt;- getRandomR (0,length xs - 1)&lt;br /&gt;&gt;                   x' &lt;- getRandom&lt;br /&gt;&gt;                   return $ replaceAt i xs x'&lt;br /&gt;&gt;     recombination xs xs' = do&lt;br /&gt;&gt;                          i &lt;- getRandomR (1,length xs - 2)&lt;br /&gt;&gt;                          let (xs1,xs2) = splitAt i xs&lt;br /&gt;&gt;                              (xs1',xs2') = splitAt i xs'&lt;br /&gt;&gt;                          return (xs1++xs2',xs1'++xs2)&lt;br /&gt;&gt; replaceAt i xs x = xs1++[x]++(drop 1 xs2)&lt;br /&gt;&gt;               where (xs1,xs2) = splitAt i xs&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;At this point we can start putting together the real framework for a genetic algorithm run.  The first, and relatively easiest function to compute will be the one to choose the mating pool for the next generation given a fitness function and a list of specimen.  I assume a constant population size for the course of the simulation, so the outgoing list will have just as many members as the in going list.  We also do our selection based entirely upon the relative fitness between the specimen of the population, an idiom captured quite well in the fromList function in the Control.Monad.Random library.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;&gt; chooseMatingPool :: MonadRandom m =&gt; (a -&gt; Integer) -&gt; [a] -&gt; m [a]&lt;br /&gt;&gt; chooseMatingPool eval pop = replicateM l $ fromList weighted&lt;br /&gt;&gt;     where weighted = map (\p -&gt; (p, eval p % 1)) pop&lt;br /&gt;&gt;           l = length pop&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now I'll admit that I'm limiting the fitness function a little by requiring it to return Integer values, but I honestly feel like that's a generality that I'm willing to lose for the purposes of this post and for the convenience of using fromList.  &lt;br /&gt;&lt;br /&gt;Next will be the handler that sexually recombines the mating pool.  I cheat a little here and presume that since the order of the mating pool was selected randomly that I don't need to shuffle them any more when I perform the selection and thus I can just take pairs of specimen, breed them, then put them back in the list.  If there's an odd man out, or as I like to call him "Creighton in High School", then we don't breed him with anyone and just put him back in the pool.&lt;br /&gt;&lt;br /&gt;The function to implement mutation in the population is also extremely trivial so I'll throw it in below without much ado.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;&gt; breed :: (MonadRandom m, Genome a) =&gt; [a] -&gt; m [a]&lt;br /&gt;&gt; breed [] = return []&lt;br /&gt;&gt; breed (x:[]) = return [x]&lt;br /&gt;&gt; breed (x:y:xs) = do&lt;br /&gt;&gt;   (x',y') &lt;- recombination x y&lt;br /&gt;&gt;   xs' &lt;- breed xs&lt;br /&gt;&gt;   return $ x':y':xs'&lt;br /&gt;&gt;&lt;br /&gt;&gt; mutate :: (MonadRandom m, Genome a) =&gt; Double -&gt; [a] -&gt; m [a]&lt;br /&gt;&gt; mutate chance pop = mapM (mutate' chance) pop&lt;br /&gt;&gt;     where mutate' c a = do&lt;br /&gt;&gt;             result &lt;- getRandomR (0,1)&lt;br /&gt;&gt;             if result &lt; c then mutation a else return a &lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Alright, so the next minor hurdle is going to be generating the initial population we need.  Now, my cheating with lists has painted us into a slight corner where we can't be as generic as we'd like.  The problem is that there are two conflicting imperatives at work here.  First, that lists are a very convenient way to deal with sets of genes.  Second, that the lists in a single simulation must all be of the same size.  The result is that I can't write any generic instance such as &lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;  instance (Random a) =&gt; Random [a] where&lt;br /&gt;    ...&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;useful in all instances, since I want to be able to use different size lists, or arrays for that matter, for different simulations.  What would be the slickest solution?  Depedently typed arrays with the size as a part of the type.  However, in a world without dependent types we can still write something that works even if the lack of clean semantics annoys me.&lt;br /&gt;&lt;br /&gt;In any case we can now start wrapping the whole thing up a bit more into larger control structures.  I think these are fairly straight forward, but the main function is runSimulation.  It takes in the number of runs to execute, the performance threshold for declaring an early end, the probability of mutation, the evaluation function, and the initial population.  That's a lot of parameters!&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;&gt; randomList :: (Random a,MonadRandom m) =&gt; Int -&gt; m [a]&lt;br /&gt;&gt; randomList i = liftM (take i) getRandoms&lt;br /&gt;&gt;&lt;br /&gt;&gt; initialListPopulation :: (Random a, MonadRandom m) =&gt; Int -&gt; Int -&gt; m [[a]]&lt;br /&gt;&gt; initialListPopulation s l = sequence $ replicate s $ randomList l&lt;br /&gt;&gt; &lt;br /&gt;&gt; simulationStep :: (MonadRandom m, Genome a) =&gt; Double -&gt; (a -&gt; Integer) -&gt; [a] -&gt; m [a]&lt;br /&gt;&gt; simulationStep mut_chance eval pop = chooseMatingPool eval pop &gt;&gt;= breed &gt;&gt;= mutate mut_chance &lt;br /&gt;&gt;   &lt;br /&gt;&gt; maxInPopulation :: (a -&gt; Integer) -&gt; [a] -&gt; (a,Integer)&lt;br /&gt;&gt; maxInPopulation f = head . reverse . sortBy (\(_,w) (_,w') -&gt; compare w w') . map (\p -&gt; (p,f p))&lt;br /&gt;&gt;&lt;br /&gt;&gt; runSimulation :: (MonadRandom m, Genome a) =&gt; Int -&gt; Integer -&gt; Double -&gt; (a -&gt; Integer) -&gt; [a] -&gt; m a&lt;br /&gt;&gt; runSimulation 0 _ _ eval pop = return $ fst $ maxInPopulation eval pop&lt;br /&gt;&gt; runSimulation runs threshold mut_chance eval pop = do                               &lt;br /&gt;&gt;                    if snd (maxInPopulation eval pop) &gt;= threshold &lt;br /&gt;&gt;                       then return $ fst (maxInPopulation eval pop)&lt;br /&gt;&gt;                       else do&lt;br /&gt;&gt;                            newpop &lt;- simulationStep mut_chance eval pop&lt;br /&gt;&gt;                            let finalpop = takeBest eval pop newpop&lt;br /&gt;&gt;                            runSimulation (runs-1) threshold mut_chance eval finalpop&lt;br /&gt;&gt;&lt;br /&gt;&gt; takeBest :: (a -&gt; Integer) -&gt; [a] -&gt; [a] -&gt; [a]&lt;br /&gt;&gt; takeBest eval xs xs' = take (length xs) . reverse . sortBy (\p p' -&gt; compare (eval p) (eval p')) $ xs++xs'&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now we have enough framework in place that we can introduce an actual, executable, example.  In accordance with a tutorial I saw once, we'll evolve the string of all 'True's as a quick test.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&lt;br /&gt;&gt; evalOnes :: [Bool] -&gt; Integer&lt;br /&gt;&gt; evalOnes = foldr (\b s -&gt; let v=if b then 1 else 0 in v+s) 0&lt;br /&gt;&gt;&lt;br /&gt;&gt; main = do&lt;br /&gt;&gt;   p &lt;- initialListPopulation 50 20&lt;br /&gt;&gt;   final &lt;- runSimulation 200 20 0.01 evalOnes p&lt;br /&gt;&gt;   print final&lt;br /&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;I've done some preliminary testing and found that for this size of problem it still quite often finds the list of 20 Trues within the 200 generations.  I'm sure if I played a bit more with how the population was chosen I could get it to be much more optimal, but I plan to worry more about that when I tweak my code to accommodate monotypic genetic &lt;em&gt;programming&lt;/em&gt; instead of just fixed length genetic algorithms.&lt;br /&gt;&lt;br /&gt;&lt;h3&gt;Random Thoughts and Idle Speculation&lt;/h3&gt;&lt;br /&gt;So first off, I found this code extremely easy to write.  Now that I'm pretty much using Haskell for all of my personal projects and toys, I've come to appreciate just how effortless writing code starts to feel.  It's just a language that stays out of my way when I'm trying to figure out a problem, and that's about the best compliment I think I can give a tool.&lt;br /&gt;&lt;br /&gt;Also, as I've continued reading Koza's book I'm starting to wonder about what exactly makes genetic programming so much more powerful than straight up genetic algorithsm.  I'm guessing it really comes down to the richness and varying size of the structure being evolved rather than the fact that you're evolving a parse tree.  There's some ideas tickling at the back of my head about what about qualities a data structure, a functor, needs to satisify to be "evolvable".  Hopefully I'll be able to clarify some thoughts about that as I continue reading the book.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-7895886698467133271?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/7895886698467133271/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=7895886698467133271' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/7895886698467133271'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/7895886698467133271'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2008/10/working-through-genetic-programming.html' title='Working through Genetic Programming'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-2642826832981971507</id><published>2008-09-30T19:50:00.001-07:00</published><updated>2008-09-30T19:59:56.744-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><category scheme='http://www.blogger.com/atom/ns#' term='frp'/><title type='text'>Some first steps with Data.Reactive</title><content type='html'>I've had a pretty busy last week and I began to go down the path of neglecting my poor, tiny blog.  Don't die on me, tiny blog!  I will grant you the content you desire to make you happy!&lt;br /&gt;&lt;br /&gt;Alright, so &lt;a href="http://panicsonic.blogspot.com/"&gt;a friend of mine&lt;/a&gt; asked me about Data.Reactive a few days ago and I wanted to share a couple of small examples and even questions about the proper use of this library.&lt;br /&gt;&lt;br /&gt;For those who haven't seen it, Conal Elliot has made a slightly brain-twisty new library for doing functional reactive programming, i.e. a way to make interactive programs with clean semantics.  What follows is my attempt to make a simple chat server that uses Data.Reactive to handle logins and echoing text.  I'm partly cribbing from a good example on &lt;a href="http://www.mail-archive.com/haskell-cafe@haskell.org/msg36375.html"&gt;haskell cafe&lt;/a&gt; and unabashedly borrow some of Mr. Stephen's function definitions.  I'm not claiming this is a &lt;em&gt;good&lt;/em&gt; example of using Data.Reactive, only that it merely works and this was my way of learning about the library.  If anyone with more experience can comment as to my use/misuse of the Conal's work, it would be most appreciated.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&gt; module Main where&lt;br /&gt;&gt;&lt;br /&gt;&gt; import Control.Concurrent&lt;br /&gt;&gt; import Control.Concurrent.STM&lt;br /&gt;&gt; import Control.Applicative&lt;br /&gt;&gt; import Control.Monad&lt;br /&gt;&gt; import Data.Reactive&lt;br /&gt;&gt; import Network&lt;br /&gt;&gt; import System.IO&lt;br /&gt;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The function socketServer is going to be our introduction to using Events in Data.Reactive.  It returns an event source that we can use to grab handles as they are created by the acceptConnection function.  An important point that I found embarrassingly confusing is that you don't need to do any plumbing between the event and sink.  The sink is just a function of type a -&gt; IO () that populates the event whenever it is called.  acceptConnection is just a simple function that accepts the the connection then passes that into the sink that we created with mkEvent.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&gt; socketServer :: IO (Event Handle)&lt;br /&gt;&gt; socketServer = withSocketsDo $ do&lt;br /&gt;&gt;                  (event,sink) &lt;- mkEvent &lt;br /&gt;&gt;                  socket &lt;- listenOn (PortNumber 5000) &lt;br /&gt;&gt;                  forkIO $ forever $ acceptConnection socket sink&lt;br /&gt;&gt;                  return event&lt;br /&gt;&gt;&lt;br /&gt;&gt; acceptConnection :: Socket -&gt; (Handle -&gt; IO ()) -&gt; IO ThreadId&lt;br /&gt;&gt; acceptConnection s sink = do&lt;br /&gt;&gt;   (h,_,_) &lt;- accept s &lt;br /&gt;&gt;   hSetBuffering h NoBuffering&lt;br /&gt;&gt;   forkIO $ sink h&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now seeing these functions, you might be wondering what you need to do to get at the data in the event that's returned by this function.  Well, we only have to take a look at the documentation for Data.Reactive on &lt;a href="http://hackage.haskell.org/packages/archive/reactive/0.5/doc/html/Data-Reactive.html"&gt;hackage&lt;/a&gt; to see that Event is an instance of Functor and that this functor instance allows us to lift a function of type a -&gt; IO b to a function Event a -&gt; Event (IO b).  Looking at the documentation again, we find a wonderful little function called runE that has type Event (IO b) -&gt; IO a so lets put these together into one tiny program. &lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&gt; main' = do&lt;br /&gt;&gt;   e &lt;- socketServer &lt;br /&gt;&gt;   runE $ fmap (\h -&gt; print h &gt;&gt; hClose h) e&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;This is a pretty braindead example, but it will print a line to stdout every time that a new connection is made to the server.  Now lets go ahead and make it so that as new events occur we launch a connection handler that allows us to turn this into a real chat room.  We'll also, just to be gratuitous, also use events to manage the incoming messages and their distribution.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&gt; main = do&lt;br /&gt;&gt;        e &lt;- socketServer &lt;br /&gt;&gt;        (msgEvent,sink) &lt;- mkEvent &lt;br /&gt;&gt;        runE $ fmap (forkIO . (handleCloser $ handler msgEvent sink)) e&lt;br /&gt;&gt; handler :: Event String -&gt; (String -&gt; IO ())-&gt; Handle -&gt; IO ()&lt;br /&gt;&gt; handler e sink h = do&lt;br /&gt;&gt;   subscribe e (hPutStrLn h)&lt;br /&gt;&gt;   forever $ hGetLine h &gt;&gt;= sink&lt;br /&gt;&gt;&lt;br /&gt;&gt; handleCloser ::  (Handle -&gt; IO ()) -&gt; Handle -&gt; IO ()&lt;br /&gt;&gt; handleCloser action h = catch (action h) (const $ hClose h)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Okay, so not really that much changed in this version.  The big change is that we now have two sets of events, one that for the handles and one for the messages.  We also use the subscribe function to launch the threads that display messages to everyone logged in, subscribe being a slightly misleadingly typed function that takes in an event and a consumer and spawns a new thread feeding the event data into the consumer.  Now, all you boys and girls following along at home will probably notice a major oversight:  at the moment, there's no real way to close down the chat server cleanly.  Also, I cheat and don't properly handle logouts except for closing the handle when it hits an error.&lt;br /&gt;&lt;br /&gt;&lt;br /&gt;I'm also working on another use of Data.Reactive with some of the SDL toys I've written.  Maybe I should port my pong clone over to it, if I have copious free time.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-2642826832981971507?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/2642826832981971507/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=2642826832981971507' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/2642826832981971507'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/2642826832981971507'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2008/09/some-first-steps-with-datareactive.html' title='Some first steps with Data.Reactive'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-8351834681707879764</id><published>2008-09-30T11:45:00.003-07:00</published><updated>2008-09-30T11:45:00.474-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='laziness'/><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><title type='text'>One last thought on laziness</title><content type='html'>So while I'm working on a couple of other posts I want to put up over the next couple of days, I did want to throw out some last words on this whole lazy evaluation business &amp;amp; advice for learning Haskell.&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;I'm of the opinion that laziness is the single hardest thing to get used to in Haskell:  not warm fuzzy things, not higher order functions, not syntax.  The reason why it's taken me awhile, having used Haskell more off than on for small toys over the past couple of years, to really grasp how to use lazy evaluation is that it forces you to think about the combination of your functions and data much more carefully.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Let's take a really silly example such as &lt;pre&gt;head . map (+1)&lt;/pre&gt; &lt;/div&gt;because it's something that is easy &amp;amp; obvious.  If you apply this function to a list of numbers the evaluation can proceed something like the following:&lt;pre&gt;head . map (+1) [1,2,..]&lt;br /&gt;head $ ((+1) 1):(map (+1) [2,...])&lt;br /&gt;((+1) 1)&lt;br /&gt;2&lt;br /&gt;&lt;/pre&gt;To anyone remotely familiar with the concept of laziness I'm sure this seems somewhat intuitive.  You only need the first element of the list, so only the first element has the argument to map applied to it.  It's a simple consequence of the structure of lists and the definition of map, the kind of example that you can feel comfortable with after just a minute with a pencil and paper.  So what's my point?&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;My point is that if you're learning Haskell and you're running into problems with laziness, you should break out the pencil &amp;amp; paper and try to calculate what will happen when your function is called.  It's something you don't really have to do with other languages, but I think it's the best way to see how your functions and data structures interact during evaluation until you have better intuition.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-8351834681707879764?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/8351834681707879764/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=8351834681707879764' title='5 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/8351834681707879764'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/8351834681707879764'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2008/09/one-last-thought-on-laziness.html' title='One last thought on laziness'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>5</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-3997134335290372353</id><published>2008-09-22T16:32:00.003-07:00</published><updated>2008-09-22T19:15:12.889-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='laziness'/><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><category scheme='http://www.blogger.com/atom/ns#' term='oh crap that was dumb'/><title type='text'>Laziness redux</title><content type='html'>Okay, so last time around I made reference to a little program to generate subscriber profiles for an e-mail system I'm testing and how it was blowing up when trying to generate over 10k profiles.  Well, like a big kid I actually managed to figure this one out for myself.  I'll include a simplified version of the problem code to illustrate the point.&lt;br /&gt;&lt;br /&gt;So the problem is that I wanted to randomly generate these user profiles, so I ended up making this data type an instance of Random which is entirely uninteresting &amp;amp; boilerplate code.&lt;br /&gt;&lt;br /&gt;Now, essentially the logic for generating the list of profiles looked like, exaggerated for full effect,&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;import Control.Monad&lt;br /&gt;import Random&lt;br /&gt;filepath = "crud.csv"&lt;br /&gt;generateProfiles :: Int -&gt; IO [Int]&lt;br /&gt;generateProfiles i = foldM aux [] [1..i]&lt;br /&gt;                   where aux is i = do&lt;br /&gt;                                sub &lt;- randomIO                                              &lt;br /&gt;                                return (sub:is) &lt;br /&gt;main = generateProfiles 10000000 &gt;&gt;= (writeFile filepath . unlines . map show)  &lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Run this!  Run this and weep for your feeble RAM as it is withers under the gaze of my space leak!&lt;br /&gt;&lt;br /&gt;Alright, so this is pretty awful isn't it?  It came from trying to think about the problem as "well, I want to generate 'i' many subscribers so I'm going to iterate over a list of i length, generating a subscriber each time".  Bzzt, wrong.  That's trying to (badly) emulate a C style for-loop in Haskell, not writing Haskell, and is a very bad idea.&lt;br /&gt;&lt;br /&gt;Well, I took a look at this code with a fresh eye, was terrified, and then realized what would probably be a more idiomatic Haskell program:  generate an infinite list of subscribers, and just write the first 'i' to a file.  After all, if I'm truly being lazy then only as many as I need to write should be created.  So the new approach looks something like&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;betterGenerate :: (RandomGen g) =&gt; g -&gt; [Int]&lt;br /&gt;betterGenerate = randoms&lt;br /&gt;&lt;br /&gt;main = do&lt;br /&gt;       std &lt;- newStdGen  &lt;br /&gt;       let subs = betterGenerate std  &lt;br /&gt;       (writeFile filepath . unlines . map show . take 10000000) subs &lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;which takes a few seconds, but doesn't eat RAM all to Hell.  The main point here, for me, was to stop trying to write C# in Haskell and just write Haskell.  There's probably still ways I could improve the logic of my little utility, but I can now generate 1 million subscribers, or about 120 MB of data, in roughly 2 minutes which is the upper limit of what I need.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-3997134335290372353?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/3997134335290372353/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=3997134335290372353' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/3997134335290372353'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/3997134335290372353'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2008/09/laziness-redux.html' title='Laziness redux'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-6549028803875990222</id><published>2008-09-19T19:07:00.003-07:00</published><updated>2008-09-19T20:07:45.465-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><title type='text'>Haskell Cafe or: How I learned to stop worrying &amp; love laziness</title><content type='html'>So as a part of my efforts to not just be so isolationist I'm starting to get code critiques on Haskell Cafe.  It makes me proud, though, to be able to make &lt;a href="http://www.haskell.org/pipermail/haskell-cafe/2008-September/047681.html"&gt;grown men weep&lt;/a&gt; with the power of my unintentional obfuscation.  Did I say proud?  I meant mildly mortified.&lt;br /&gt;&lt;br /&gt;Indeed though, the feedback was actually rather helpful and it made me realize something:  I still naturally avoid laziness.  I mean, I take advantage of the ability to define control structures via laziness, but relying on laziness to give you incremental processing of a file?  I still find that a little scary &amp;amp; unintuitive.  I feel like an ape trying to understand the proper uses of fire:  not entirely cognizant of the proper outcome but instinctively aware that I could bring everything down in flames.&lt;br /&gt;&lt;br /&gt;How do I overcome this?  Experience I suppose.  That and perhaps judiciously looking at the ghc-core output to understand what the compiler is really doing.&lt;br /&gt;&lt;br /&gt;I actually have a slightly less trivial utility for generating fake subscriber profiles for testing an e-mail system I'm working on that, despite working in ~2 seconds for 10k profiles, exhausts its available memory after about 10 minutes when I try to generate 100k profiles.  Yikes!  So I'm guessing I'm misusing laziness somehow and building up a massive amount of thunks, and as Cee-Lo Green almost said "I ain't got no time to be thunkin' around".  I want to try digging into the generated core, doing some profiling, and finding out what is really what before I ask h-cafe again.  It'll put hair on my chest.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-6549028803875990222?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/6549028803875990222/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=6549028803875990222' title='55 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/6549028803875990222'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/6549028803875990222'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2008/09/haskell-cafe-or-how-i-learned-to-stop.html' title='Haskell Cafe or: How I learned to stop worrying &amp; love laziness'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>55</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-817235713138085894</id><published>2008-09-17T11:30:00.000-07:00</published><updated>2008-09-17T10:24:09.086-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><category scheme='http://www.blogger.com/atom/ns#' term='C#'/><title type='text'>Predictability in APIs</title><content type='html'>So this is a minor rant about something that bothers me in C# that I felt like sharing over lunch.  First, I'd like to make the obligatory disclaimer that I actually like C# quite a bit.  It's a close third behind Common Lisp on my list of language love.&lt;div&gt;&lt;br /&gt;&lt;div&gt;The problem I have, though, is that functions that return objects may actually return null and that this is not reflected in the type system.  I find this especially frustrating because they're so close to the right track with the nullable types.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;If you ever play with LINQ to SQL you'll undoubtably come across nullable types.  If your database has a column of type INT, but nulls are allowed, LINQ doesn't give you a type int for that column:  it gives you type int?, which is really just the .NET equivalent of Maybe Int.  You can't just willy nilly pretend you have an int when you may not because this gets caught as a type error.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Functions that return objects, on the other hand, don't do this because null is a valid assignment to any variable of an object type.  This bugs the hell out of me because you can't tell just by looking at type of a function whether or not there are circumstances where it will return null instead of a 'real' object.  This means that I'll either get bitten on the patootie at some point when a function I thought never returned null actually does, or I need to preemptively wrap try's around all over the place as some form of voodoo to ward off bad spirits.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;My basic point is predictability.  I want to be able to use a library in the most naive &amp;amp; dumb way as possible and still not have it blow up in my face.  This is one thing I thing Haskell definitely gets right with functors such as Maybe or Either.&lt;/div&gt;&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-817235713138085894?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/817235713138085894/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=817235713138085894' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/817235713138085894'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/817235713138085894'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2008/09/predictability-in-apis.html' title='Predictability in APIs'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-3110407190153182900</id><published>2008-09-17T08:37:00.002-07:00</published><updated>2008-09-17T09:04:48.678-07:00</updated><title type='text'>Reading List #1</title><content type='html'>So I'm starting a weekly reading list that I'm hoping will be useful to my compadres.  The first two things I'm recommending are&lt;div&gt;&lt;ul&gt;&lt;li&gt;Chapters 1 &amp;amp; 2 of the awesome &lt;a href="http://people.redhat.com/drepper/cpumemory.pdf"&gt;"What Every Programmer Should Know About Memory"&lt;/a&gt; though this makes for rather dense reading, at least for me, I think even just gleaning the low level picture is instructive.&lt;/li&gt;&lt;li&gt;The old classic "&lt;a href="http://www.cs.chalmers.se/~rjmh/Papers/whyfp.html"&gt;Why Functional Programming Matters&lt;/a&gt;" by John Hughes.  It's well written, still feels relevant, &amp;amp; is worth reading just for the comparison of functional programmers to ascetic monks.&lt;/li&gt;&lt;/ul&gt;For my own extra reading, I'm going through the first three chapters of &lt;a href="http://www.amazon.com/Genetic-Programming-Computers-Selection-Adaptive/dp/0262111705"&gt;Koza I&lt;/a&gt; and the paper "&lt;a href="http://www.informatik.uni-bonn.de/~ralf/publications/Contract.pdf"&gt;Typed Contracts for Functional Programming&lt;/a&gt;".  I'll have at least a paragraph or two to throw out there about each of these on Sunday.&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-3110407190153182900?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/3110407190153182900/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=3110407190153182900' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/3110407190153182900'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/3110407190153182900'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2008/09/reading-list-1.html' title='Reading List #1'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-452501506532897286</id><published>2008-09-16T16:55:00.003-07:00</published><updated>2008-09-16T17:31:18.936-07:00</updated><title type='text'>Events that have occurred</title><content type='html'>So a lot has happened over the past few months.  &lt;div&gt;&lt;ul&gt;&lt;li&gt;I left one job and started a new job as a programmer/data center admin at a company called &lt;a href="http://claritytech.com/"&gt;Clarity Technology Group&lt;/a&gt;.  It's a much smaller company than what I had been at &amp;amp; is a work environment better suited to me.&lt;br /&gt;&lt;/li&gt;&lt;li&gt;I've discovered that &lt;a href="http://www.vermontvalley.com/home.htm"&gt;fresh vegetables&lt;/a&gt; are very helpful when you're trying to go on a diet.&lt;/li&gt;&lt;li&gt;I've decided to improve my &gt;2:1 ratio of blog drafts to blog posts.&lt;/li&gt;&lt;li&gt;I've started writing bindings to VMWare's VIX API in Haskell.&lt;/li&gt;&lt;/ul&gt;Now as for the VIX bindings, I haven't gotten very far yet but I have to give a shout out to the writers of &lt;a href="http://book.realworldhaskell.org/"&gt;Real World Haskell&lt;/a&gt; for writing a rather excellent introductory chapter on Haskell's FFI.  It's a lot less scary than I thought it would be and that's a credit to the authors.  I consider teaching to be the art of making things seem as simple as they truly are, and their explanation certainly succeeds there.&lt;/div&gt;&lt;div&gt;&lt;br /&gt;&lt;/div&gt;&lt;div&gt;Also, as a general question to the Haskellers out there:  does anyone have experience calling WMI from Haskell?  Are there bindings that are useful for this task?&lt;/div&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-452501506532897286?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/452501506532897286/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=452501506532897286' title='10 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/452501506532897286'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/452501506532897286'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2008/09/events-that-have-occurred.html' title='Events that have occurred'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>10</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-8140538577956612340</id><published>2008-04-01T19:37:00.003-07:00</published><updated>2008-09-16T16:54:04.583-07:00</updated><title type='text'>Intro to SDL with Haskell</title><content type='html'>So for awhile now I've been working on the &lt;a href="http://lazyfoo.net/SDL_tutorials/index.php"&gt;lazyfoo&lt;/a&gt; tutorials using Haskell's SDL &lt;a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/SDL-0.5.3"&gt;bindings&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;I thought it might not be a bad idea to throw up some of the final code.  Now one caveat is that I'm going to assume that if you're playing along at home that you have downloaded any materials needed for the tutorial and have it in the same directory as the executable that you're running.&lt;br /&gt;&lt;br /&gt;I'll skip tutorial 1 because it's a little too trivial, but below is the code for the second tutorial.&lt;a href="http://hackage.haskell.org/cgi-bin/hackage-scripts/package/SDL-0.5.3"&gt;&lt;span style="font-weight: bold;"&gt;&lt;/span&gt;&lt;/a&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&gt; import Prelude&lt;br /&gt;&gt; import Graphics.UI.SDL as SDL&lt;br /&gt;&lt;br /&gt;&gt; background = "background.bmp"&lt;br /&gt;&gt; hello = "hello_world.bmp"&lt;br /&gt;&lt;br /&gt;&gt; main = do&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The first thing we have to do is initialize the SDL subsystems.  For simplicity,&lt;br /&gt;I always just do init [InitEverything].&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&gt;   SDL.init [InitEverything]&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Next, we create a small, vanilla, window using setVideoMode&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&gt;   setVideoMode 640 480 32 []&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Since the images are just bitmaps, we can just use the straight up loadBMP functions.&lt;br /&gt;loadBMP returns a surface, which is the fundamental unit for drawing in SDL.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&gt;   image &lt;- loadBMP hello&lt;br /&gt;&gt;   back &lt;- loadBMP background&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Next we need to grab the surface that we want to draw to.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&gt;   screen &lt;- getVideoSurface&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;And the two blitSurface commands to actually paint the contents of one surface&lt;br /&gt;onto another.  The arguments are the source surface, the clipping rectangle of&lt;br /&gt;this surface, the target surface, and the rectangle to which you want to paint.&lt;br /&gt;In both cases, Nothing represents the entire surface.  That's why when painting&lt;br /&gt;the background both rectangles are Nothing.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&gt;   blitSurface back Nothing screen Nothing&lt;br /&gt;&gt;   blitSurface image Nothing screen (Just (Rect 180 140 0 0))&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Finally, we need to actually draw the surface on the screen using flip.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&gt;   SDL.flip screen&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;The following function uses events to make sure that the window will stay open&lt;br /&gt;until you choose to close it.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&gt;   quitHandler&lt;br /&gt;&lt;br /&gt;&gt; quitHandler :: IO ()&lt;br /&gt;&gt; quitHandler = do&lt;br /&gt;&gt;   e &lt;- waitEvent&lt;br /&gt;&gt;   case e of&lt;br /&gt;&gt;     Quit -&gt; return ()&lt;br /&gt;&gt;     otherwise -&gt; quitHandler&lt;br /&gt;&lt;/pre&gt;&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-8140538577956612340?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/8140538577956612340/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=8140538577956612340' title='6 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/8140538577956612340'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/8140538577956612340'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2008/04/intro-to-sdl-with-haskell.html' title='Intro to SDL with Haskell'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>6</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-2868711268382850809</id><published>2008-02-05T03:40:00.000-08:00</published><updated>2008-02-05T18:26:05.349-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='performance'/><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><title type='text'>Thoughts on Haskell &amp; Performance</title><content type='html'>So I'm trying to ease my way back into blogging and I thought I'd start with some thoughts I had that came from &lt;a href="http://reddit.com/r/programming/info/67o8d/comments/c033dof"&gt;this&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;Now, my current job involves analyzing performance bottlenecks for a decent sized software company &amp;amp; then working with the individual R&amp;amp;D teams to make improvements.&lt;br /&gt;&lt;br /&gt;My point is that from my own experiences, the quality of your compiler isn't the bottleneck.  It's your design.&lt;br /&gt;&lt;br /&gt;I'm not even making the obvious point that "you choose stupid algorithms you get stupid performance".  I mean that when I have found application level issues they generally have either been bugs or they have been cases where the semantics for that feature of the app aren't compatible with high performace, e.g. some screen  will too eagerly load request data from the database, too aggressively do calculations that could be delayed till later in the UI, etc.  I've worked this job for about a year and I haven't yet had a time when I've found that our choice of language, &lt;span style="font-style: italic;"&gt;VB6&lt;/span&gt;, has been the major problem.&lt;br /&gt;&lt;br /&gt;My conclusion is that for things that aren't numerical analysis or video games, for applications that are real "pay the bills" software, the fact that something like Haskell is slower than C just doesn't seem that relevant.&lt;br /&gt;&lt;br /&gt;Although, now that I think about it I'm not sure if it matters for those &lt;a href="http://www.londonhug.net/2007/09/24/better-video-for-games-in-haskell/"&gt;other&lt;/a&gt; &lt;a href="http://www.cse.unsw.edu.au/%7Echak/papers/KCCSB08.html"&gt;things&lt;/a&gt; either.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-2868711268382850809?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/2868711268382850809/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=2868711268382850809' title='3 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/2868711268382850809'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/2868711268382850809'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2008/02/thoughts-on-haskell-performance.html' title='Thoughts on Haskell &amp; Performance'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>3</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-2106735907359163911</id><published>2007-06-01T15:42:00.000-07:00</published><updated>2007-06-01T15:50:31.694-07:00</updated><title type='text'>Exokernels &amp; Typeclasses</title><content type='html'>Blahblah sick blahblah tired blahblah giant antibiotic pills blah&lt;br /&gt;&lt;br /&gt;Okay, so one thing that I was thinking about a long time ago when I reread the House paper was that the whole notion of the H monad, a restricted version of the IO monad meant for interacting with the OS, was really a lot like a specification of an exokernel. &lt;br /&gt;&lt;br /&gt;I don't think the analogy is perfect, but I do think that something like the H monad combined with a plug-ins system for Haskell could actually be used to make something very similar to an exokernel with external libraries providing the real meat of normal OS abstractions to processes.&lt;br /&gt;&lt;br /&gt;I need to think about this a bit more.&lt;br /&gt;&lt;br /&gt;I also would like to do chunks of the book &lt;a href="http://www.google.com/url?sa=t&amp;ct=res&amp;amp;cd=2&amp;url=http%3A%2F%2Fwww.cs.man.ac.uk%2F%7Edavid%2Fcategories%2Fbook%2Fbook.pdf&amp;amp;ei=O6JgRriLI5GajgG4vbCOBQ&amp;usg=AFQjCNEFAsaluKtqZ1cr65eV4VY9dxsLIA&amp;amp;sig2=N6agc3ZEmpycafNabfXi6g"&gt;Computational Category Theory&lt;/a&gt; in Haskell, just to make myself sit down and really get comfortable with the way that book approaches the subject.  Different takes on familiar subjects are always nice.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-2106735907359163911?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/2106735907359163911/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=2106735907359163911' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/2106735907359163911'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/2106735907359163911'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2007/06/exokernels-typeclasses.html' title='Exokernels &amp; Typeclasses'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-4875256644821422061</id><published>2007-05-10T10:17:00.000-07:00</published><updated>2007-05-10T10:36:08.155-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><title type='text'>A couple of silly examples</title><content type='html'>So having being mostly stumped on a few other ideas, I was rereading a textbook on OS design and saw that one of the exercises was to create an echo server.  I thought I'd clean up one I had written in the past to learn the Network library and post it up here.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&gt;port :: PortID&lt;br /&gt;&gt;port = PortNumber 6000&lt;br /&gt;&lt;br /&gt;&gt;main = withSocketsDo $ do&lt;br /&gt;&gt; sock &lt;- listenOn port &lt;br /&gt;&gt; handler sock&lt;br /&gt;&lt;br /&gt;&gt;handler :: Socket -&gt; IO ()&lt;br /&gt;&gt;handler s = do&lt;br /&gt;&gt;  (h,_,_) &lt;- accept s &lt;br /&gt;&gt;  hSetBuffering h NoBuffering&lt;br /&gt;&gt;  forkIO $ echo h&lt;br /&gt;&gt;  handler s&lt;br /&gt;&lt;br /&gt;&gt;echo :: Handle -&gt; IO ()&lt;br /&gt;&gt;echo h= do&lt;br /&gt;&gt;  text &lt;- liftM (filter (/='\r')) $ hGetLine h &lt;br /&gt;&gt;  if text=="exit"&lt;br /&gt;&gt;     then hClose h&lt;br /&gt;&gt;     else do&lt;br /&gt;&gt;          hPutStrLn h text&lt;br /&gt;&gt;          echo h&lt;br /&gt;&gt;&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;If you run this and telnet to localhost 6000 you should be able to see it work.  Actually writing this code was very simple and felt very intuitive.&lt;br /&gt;&lt;br /&gt;Now, that's pretty simple and a nice start:  now let's say we wanted a simple server that can handle connections, creating logins, and validating logins. The problem is that now the threads need to share some kind of information, and that makes things a lot more messy; however, Software Transactional Memory makes it a bit easier.&lt;br /&gt;&lt;br /&gt;We'll take a very silly way to store usernames and passwords, as tuples in some list.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&gt;type Login = (String,String)&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now our actual "database" of logins will be a STM TVar of a list of logins.  For those unfamiliar with STM, I really do recommend reading some of the original papers.  They're rather well written and clear in motivating how one would use STM.  For now, all that matters is that a TVar is a mutable object that can be accessed and modified atomically.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&gt;type DB = TVar [Login]&lt;br /&gt;&lt;br /&gt;&gt;main = do&lt;br /&gt;&gt; db &lt;- newTVarIO [] &lt;br /&gt;&gt; sock &lt;- listenOn port &lt;br /&gt;&gt; handler sock db&lt;br /&gt;&lt;br /&gt;&gt;handler :: Socket -&gt; DB -&gt; IO ()&lt;br /&gt;&gt;handler s db = do&lt;br /&gt;&gt;  (h,_,_) &lt;- accept s &lt;br /&gt;&gt;  hSetBuffering h NoBuffering&lt;br /&gt;&gt;  forkIO $ loginServer h db&lt;br /&gt;&gt;  handler s db&lt;br /&gt;&lt;br /&gt;&gt;loginServer :: Handle -&gt; DB -&gt; IO ()&lt;br /&gt;&gt;loginServer h db = do&lt;br /&gt;&gt;  hPutStrLn h "Welcome to my server, log in or create an account:  "&lt;br /&gt;&gt;  hPutStrLn h "[0]:log in\n[1]:create account\n[2]:exit"&lt;br /&gt;&gt;  choice &lt;- liftM (filter (/='\r')) $  hGetLine h &lt;br /&gt;&gt;  case choice of&lt;br /&gt;&gt;    "0" -&gt; validate h db&lt;br /&gt;&gt;    "1" -&gt; create h db&lt;br /&gt;&gt;    "2" -&gt; hClose h&lt;br /&gt;&gt;    _ -&gt; loginServer h db&lt;br /&gt;&gt;&lt;br /&gt;&gt;validate :: Handle -&gt; DB -&gt; IO ()&lt;br /&gt;&gt;validate h db = do&lt;br /&gt;&gt;  hPutStr h "username:  "&lt;br /&gt;&gt;  name &lt;- liftM (filter (/='\r')) $ hGetLine h &lt;br /&gt;&gt;  hPutStr h "password:  "&lt;br /&gt;&gt;  pass &lt;- liftM (filter (/='\r')) $ hGetLine h&lt;br /&gt;&gt;  (found,pass') &lt;- atomically $ loginLookup name db&lt;br /&gt;&gt;  if found &amp;&amp; (pass'==pass)&lt;br /&gt;&gt;    then hPutStrLn h "You can log in!"&lt;br /&gt;&gt;    else hPutStrLn h "Not valid."&lt;br /&gt;&gt;  loginServer h db&lt;br /&gt;&gt;             &lt;br /&gt;&gt;create :: Handle -&gt; DB -&gt; IO ()&lt;br /&gt;&gt;create h db = do&lt;br /&gt;&gt;  hPutStr h "username:  "&lt;br /&gt;&gt;  name &lt;- liftM (filter (/='\r')) $ hGetLine h &lt;br /&gt;&gt;  (found,_) &lt;- atomically $ loginLookup name db &lt;br /&gt;&gt;  if found&lt;br /&gt;&gt;    then hPutStrLn h "Name already in use!"&lt;br /&gt;&gt;    else do&lt;br /&gt;&gt;         hPutStr h "Choose a password:  "&lt;br /&gt;&gt;         pass &lt;- liftM (filter (/='\r')) $ hGetLine h &lt;br /&gt;&gt;         atomically $ pushDB name pass db&lt;br /&gt;&gt;         hPutStrLn h "Account created"&lt;br /&gt;&gt;  loginServer h db&lt;br /&gt;&gt;&lt;br /&gt;&gt;loginLookup :: String -&gt; DB -&gt; STM (Bool,String)&lt;br /&gt;&gt;loginLookup name db = do&lt;br /&gt;&gt;    db' &lt;- readTVar db &lt;br /&gt;&gt;    case lookup name db' of&lt;br /&gt;&gt;      Nothing -&gt; return (False,"")&lt;br /&gt;&gt;      Just p -&gt; return (True,p)&lt;br /&gt;&gt;&lt;br /&gt;&gt;pushDB :: String -&gt; String -&gt; DB -&gt; STM ()&lt;br /&gt;&gt;pushDB name pass db = do&lt;br /&gt;&gt;  db' &lt;- readTVar db &lt;br /&gt;&gt;  writeTVar db ((name,pass):db')&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now this isn't the cleanest code, and I'm worried I may have missed some edge cases that can make it fail, but for the most part I think this is a pretty decent example of shared transactional memory combined with the Network library.  The main point is that STM allows us to mostly ignore issues of how to keep everything synched together.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-4875256644821422061?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/4875256644821422061/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=4875256644821422061' title='22 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/4875256644821422061'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/4875256644821422061'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2007/05/couple-of-silly-examples.html' title='A couple of silly examples'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>22</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-2184278398128169718</id><published>2007-04-19T11:14:00.000-07:00</published><updated>2007-04-19T10:35:21.526-07:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='arrows'/><category scheme='http://www.blogger.com/atom/ns#' term='matrioshka'/><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><title type='text'>Arrows &amp; Security</title><content type='html'>I've been rereading an interesting paper from last year:  &lt;a href="http://www.cis.upenn.edu/%7Estevez/papers/LZ06a.pdf"&gt;Encoding Information Flow in Haskell&lt;/a&gt;.&lt;br /&gt;&lt;br /&gt;In a nutshell, the paper is about encoding security lattices in Haskell via arrows.&lt;br /&gt;To start with, I should say a few words about lattices.  A lattice is, fundamentally, a set with a partial order, a least upper bound binary operator, and a greatest lower bound binary operator.  I'm just going to be simple here and consider only bounded lattices where there is an actual least and greatest element for the entire lattice.&lt;br /&gt;&lt;br /&gt;Now how does a lattice tie in with security?  Well, I found that the &lt;a href="http://portal.acm.org/citation.cfm?doid=360051.360056"&gt;original paper&lt;/a&gt; on the subject is a very good introduction, but the basic idea is that any sane arrangement of security labels that can be assigned should form a lattice.  For example, if you have two security labels then you have privileges greater than or equal to either of  them.&lt;br /&gt;&lt;br /&gt;Matrioshka, our planned OS kernel, uses three lattices along with type-level capabilities to completely describe any information policy.  In case it's not immediately clear why one cannot include lattice information in the capabilities, the reason is that Haskell doesn't have true dependent types so comparisons on the type level are boolean in nature.  The types match or they do not.  You can't examine the types and decide whether one is "greater" than the other in some sense.&lt;br /&gt;&lt;br /&gt;Now this paper advocates using arrows as an interface to describe protected computations.  Essentially, you wrap up functions with the extra data describing the lattice information and then use the standard arrows typeclasses to handle control flow and composition. I actually think it's a rather neat approach.&lt;br /&gt;&lt;br /&gt;So the basic data structure involved is the FlowArrow&lt;br /&gt;&lt;pre&gt;data FlowArrow l a b c = FA {&lt;br /&gt;  computation :: a b c,&lt;br /&gt;  flow :: Flow l,&lt;br /&gt;  constraints :: [Constraint l]}&lt;/pre&gt;A FlowArrow is a wrapper around any other arrow type that also includes the change in lattice point for the computation and a list of constraints on the lattice generated by the composition of FlowArrows.  This list of constraints is then matched against the lattice and if everything checks out the computation is unwrapped and can be executed.  Pretty slick.&lt;br /&gt;&lt;br /&gt;Of course, we can add phantom types to the FlowArrow pretty easily and thus get some representation of actual capabilities.&lt;br /&gt;&lt;pre&gt;data CapArrow caps l a b c = CA (FlowArrow l a b c) &lt;/pre&gt;So now we require that for arrows to be composed together, the capabilities must be of the same type.  This is where Haskell's polymorphism pays off as we can then compose arrows that have capability requirements such as&lt;br /&gt;&lt;pre&gt;readArrow :: CapArrow (Read,d) l a b c&lt;/pre&gt;and&lt;br /&gt;&lt;pre&gt;writeArrow :: CapArrow (d,Write) l a b c&lt;/pre&gt;if the user had possession of a resource with the proper permissions attached to it&lt;br /&gt;&lt;pre&gt;initArrow :: Resource caps b -&gt; CapArrow caps l a b b&lt;/pre&gt;Now, a lot of this is still speculation because I have no hard prototype.  In terms of a system built on top of House, the underlying arrow instance would probably be Kleisli arrows for the H monad.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-2184278398128169718?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/2184278398128169718/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=2184278398128169718' title='15 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/2184278398128169718'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/2184278398128169718'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2007/04/arrows-security.html' title='Arrows &amp; Security'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>15</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-4362939433107533975</id><published>2007-04-09T06:03:00.000-07:00</published><updated>2007-04-09T06:34:34.992-07:00</updated><title type='text'>Science of Structure</title><content type='html'>In an effort to get back in the habit of writing here, I thought I'd throw out something less technical.&lt;br /&gt;&lt;br /&gt;One of my main interests is mathematics.  Like a lot of people who love math, I end up getting the typical "oh I'm not good at math" or "I never liked math" responses when I tell people this.  I try to clarify the situation by pointing out that it's not math they dislike, it's arithmetic.  Arithmetic is all the algebra, long division, how-do-I-multiply-fractions business that most people associate as Math with a scary capitol M.  That's not math, it's mechanism.  To me, mathematics is the science of structure.  It's the science that at a fundamental level tries to both abstract away phenomenon to their core essentials and illustrate the deep connections between the seemingly disparate. &lt;br /&gt;&lt;br /&gt;Given this characterization, it probably is no surprise that my favorite branch of mathematics is category theory.  I find this "abstract nonsense" to be rather inspiring in it's ability to connect ideas and concepts together, to serve as a framework for abstraction.  What's more are the apparently rich ties to computer science.  Haskell's monads may seem like the proverbial dead horse here, but they really are an excellent example. &lt;br /&gt;&lt;br /&gt;I have been studying category in my spare time for several months now.  My main book is MacLane's "Categories for the Working Mathematician".  I think it's a very dense, but very good, book.  My recommendation for study from it is to spread it out over short periods.  Don't try and sit down and absorb fifty pages of this book at once, it won't work.  Just read a single section, do a couple of the proofs, and then go back to something else for the rest of the day.  I find it's a pretty good book to work on during lunch breaks, if your company is nice enough to give you hour long ones.&lt;br /&gt;&lt;br /&gt;There are a few mathematical ideas that I've been kicking around lately:  first, how does one generalize the notion of continuous function &amp; homotopy to categories instead of topologic spaces.  Now, I did some skimming around and found that continuous functors are defined as ones that preserve limits in a category but I realized that I'm not sure if this is just a meaningless pun or if limits in a category really do have the same meaning as limits in a topologic space.  Second, is a general interest of mine in mathematical foundations of genetic programming and genetic algorithms.  Not in terms of convergence and all that, but more in terms of what structure you need to have on the genotype and the transformation to phenotype in order to have a system able to evolve.  For example, it seems like you need to have some sort of zipper-like structure on the genotype in order to do crossover.  I haven't thought about it too much though.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-4362939433107533975?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/4362939433107533975/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=4362939433107533975' title='2 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/4362939433107533975'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/4362939433107533975'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2007/04/science-of-structure.html' title='Science of Structure'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>2</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-1541588354699213598</id><published>2007-03-07T09:16:00.000-08:00</published><updated>2007-03-07T09:20:37.917-08:00</updated><title type='text'>Ball of MUD</title><content type='html'>How would one write a MUD codebase in a functional language like Haskell, or even in a multi-paradigm language such as Common Lisp?  That's something I really want to figure out, and so I'm beginning.  Four-five hours per week of hacking on it should be feasible, yet allow there to be some modicum of progress each week.&lt;br /&gt;&lt;br /&gt;I have 40-50 pages of design notes I wrote up over the fall, but haven't had time to implement any of it until now.  The very first thing to do is understand how to set up some kind of very simple server that let's a user make an account and log in.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-1541588354699213598?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/1541588354699213598/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=1541588354699213598' title='0 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/1541588354699213598'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/1541588354699213598'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2007/03/ball-of-mud.html' title='Ball of MUD'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>0</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-8143089473043814416</id><published>2007-02-21T12:45:00.000-08:00</published><updated>2007-03-02T14:27:54.872-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='matrioshka'/><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><category scheme='http://www.blogger.com/atom/ns#' term='epigram'/><title type='text'>Dependent types &amp; security</title><content type='html'>During my last semester in grad school, before I left physics with a Master's, I took the graduate course on OS design.  That was probably the second most fun class I ever took, second only because the professor was not an awesome old man we could call Yoda.&lt;br /&gt;&lt;br /&gt;In any case, in this OS class I worked on a design project for a kernel written in Haskell that employs higher order types to create a static capability system.  Beyond simply being a capability system, however, we wanted to encode actual secrecy and integrity levels into the type system as well and attach that data to all system resources.  Of course, we ran into the limitations of even Haskell's Sexy Types(tm) and found that what we really wanted were true dependent types.  Not having the time to examine the feasibility of a kernel design in Epigram, though what a kernel it would be, we ended up tagging system resources with phantom types to represent the capabilities themselves and stored the secrecy and integrity levels as actual data.  We called it Matrioshka and I would love to build a real prototype on top of House in the not too distant future.&lt;br /&gt;&lt;br /&gt;Now, the fun part is what happens when you try to express something like a capability in a dependently typed language.  It turns out to be rather simple.&lt;br /&gt;&lt;br /&gt;Let's take, as a simple example, capabilities for an arbitrary resource with only a secrecy level.  This is going to be a bit of a half-baked example, because I'm still trying to digest Epigram, but hopefully it will be somewhat illustrative anyway.&lt;br /&gt;&lt;br /&gt;So let's consider a process as just some type with an attached secrecy level.  Then we should be able to evaluate whether or not we can use a read capability to a resource, and the bit of epigram code that follows allows just that.&lt;br /&gt;&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;data Nat : *  where zero : Nat ;  succ : Nat -&gt; Nat&lt;br /&gt;-------------------------------------------------&lt;br /&gt;data Bool : *  where false : Bool ;  true : Bool&lt;br /&gt;-------------------------------------------------&lt;br /&gt;     (  x, y : Nat   !                     &lt;br /&gt;let  !---------------!                     &lt;br /&gt;     ! le x y : Bool )                     &lt;br /&gt;                                           &lt;br /&gt;     le x y &lt;= rec x                       &lt;br /&gt;     { le x y &lt;= case x                    &lt;br /&gt;       { le zero y =&gt; true                 &lt;br /&gt;         le (succ x) y &lt;= case y           &lt;br /&gt;         { le (succ x) zero =&gt; false       &lt;br /&gt;           le (succ x') (succ x) =&gt; le x' x&lt;br /&gt;         }                                 &lt;br /&gt;       }                                   &lt;br /&gt;     }                                     &lt;br /&gt;---------------------------------------------------&lt;br /&gt;inspect le (succ zero) zero =&gt; false : Bool&lt;br /&gt;---------------------------------------------------&lt;br /&gt;data Read : *  where read : Read ;  illit : Read&lt;br /&gt;---------------------------------------------------&lt;br /&gt;     ( n : Nat ;  X : * !        (      x : X      !&lt;br /&gt;data !------------------!  where !-----------------!&lt;br /&gt;     !   Cap n X : *    )        ! cap x : Cap n X )&lt;br /&gt;---------------------------------------------------&lt;br /&gt;     (  n : Nat   !                         &lt;br /&gt;data !------------!  where (---------------!&lt;br /&gt;     ! Proc n : * )        ! proc : Proc n )&lt;br /&gt;----------------------------------------------------&lt;br /&gt;     ( p : Proc n ;  c : Cap m Read !          &lt;br /&gt;let  !------------------------------!          &lt;br /&gt;     !   canRead _n _m p c : Bool   )          &lt;br /&gt;                                               &lt;br /&gt;     canRead _ n _ m p c &lt;= case c             &lt;br /&gt;     { canRead _ n _ m p (cap c) &lt;= case c     &lt;br /&gt;       { canRead _ n _ m p (cap read) =&gt; le m n&lt;br /&gt;         canRead _ n _ m p (cap illit) =&gt; false&lt;br /&gt;       }                                       &lt;br /&gt;     }                                         &lt;br /&gt;---------------------------------------------------&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;&lt;br /&gt;Now there might be a serious question as to why one would ever want to do this.  After all, if you're just analyzing the secrecy &amp; integrity levels at runtime anyway then why not just store everything as data and forget all these fancy-pants type systems? &lt;br /&gt;&lt;br /&gt;There are two major reasons, in my opinion, of why you would want to handle all security at the type level:  first, so that you can use the type system to help prove  that the system is working correctly.  Second, to improve performance!&lt;br /&gt;&lt;br /&gt;Performance is important in an OS, and by using the type system we can save quite a bit of work.  First, analysis of types should be in principle faster than actually accessing data stored in the capability itself.  Second, it should be possible to designate a working set of capabilities that a process can name &lt;span style="font-weight: bold;"&gt;and&lt;/span&gt; access securely in accordance with the secrecy and integrity lattices.  After this set has been calculated once, then the kernel will no longer have to interpose itself for security checks until the working set changes again.  &lt;br /&gt;&lt;br /&gt;Hopefully, with this potential performance gain we can have our cake and eat it too when it comes to using a functional language for the kernel design.  Of course, these claims remain just that until a prototype is completed.  As I already alluded, House is probably going to be the most feasible system in which to implement a prototype but it will likely be quite a bit of work.&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-8143089473043814416?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/8143089473043814416/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=8143089473043814416' title='1 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/8143089473043814416'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/8143089473043814416'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2007/02/dependent-types-categories-security.html' title='Dependent types &amp; security'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>1</thr:total></entry><entry><id>tag:blogger.com,1999:blog-2615156186192493130.post-8640248175803711548</id><published>2007-02-19T17:38:00.000-08:00</published><updated>2007-02-21T20:22:24.774-08:00</updated><category scheme='http://www.blogger.com/atom/ns#' term='haskell'/><title type='text'>Sussman, Robustness, &amp; Quickcheck</title><content type='html'>Today on reddit there was a link to a paper by Gerald Sussman about how to construct robust systems.&lt;br /&gt;If I understood correctly, his thesis is that one can only gain the robustness of biological systems by emulating their development:  evolution and exploratory development.  Not only that, but an emphasis on runtime tests and checks can help catch problems and further improve the strength of the system.&lt;br /&gt;&lt;br /&gt;The idea makes a lot of sense when I think about it, but I have a feeling a lot of people who read it are going to take it as an argument for dynamically typed tools.  It may have even been intended as such, but I do not presume to know the mind of Prof. Sussman.&lt;br /&gt;&lt;br /&gt;On the other hand, I think a truly powerful type system may in fact help with exploratory programming and test-driven programming.  When reading the paper I couldn't help but think of the beautiful Haskell system, &lt;a href="http://haskell.org/haskellwiki/Introduction_to_QuickCheck"&gt;QuickCheck&lt;/a&gt;.  QuickCheck actually comes with GHC, so if you're using that compiler then  you don't have to worry about installing anything else.&lt;br /&gt;&lt;br /&gt;I actually think it'd be nice to have another example than the intro to the wiki, so I'm including my own stupid one:  attempting to verify that a breadth-first search doesn't suck given that I already have some search that I know works.&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&gt;import Test.QuickCheck&lt;br /&gt;&lt;br /&gt;&gt;data Tree a = Node a | Branch (Tree a) a (Tree a)&lt;br /&gt;&gt;       deriving Show&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;So here we've defined a very simple binary tree, yay!&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&gt;dfs :: Eq a =&gt; a -&gt; Tree a -&gt; Bool&lt;br /&gt;&gt;dfs a (Node x) = a==x&lt;br /&gt;&gt;dfs a (Branch t x t') | x==a = True&lt;br /&gt;&gt;                      | otherwise = dfs a t || (dfs a t')&lt;br /&gt;&lt;br /&gt;&gt;bfs :: Eq a =&gt; a -&gt; Tree a -&gt; Bool&lt;br /&gt;&gt;bfs a tree = bfh tree []&lt;br /&gt;&gt;    where bfh (Node x) [] = x==a&lt;br /&gt;&gt;          bfh (Node x) (l:ls) = if x==a then True else bfh l ls&lt;br /&gt;&gt;          bfh (Branch t x t') l = if x==a &lt;br /&gt;&gt;                                   then True &lt;br /&gt;&gt;                                   else bfh (head l') (tail l')&lt;br /&gt;&gt;            where l' = l++[t,t']&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;Now we have two very simple forms of search.  Let's now assume that God himself has descended and told us that our depth first search is &lt;a href="http://www.clifffacecomics.com/carlhome.html"&gt;The Awesome&lt;/a&gt; but we are worried that the breadth first search doesn't work.  QuickCheck to the rescue!&lt;br /&gt;&lt;pre&gt;&lt;br /&gt;&gt;instance (Arbitrary a) =&gt; Arbitrary (Tree a) where&lt;br /&gt;&gt;    arbitrary = oneof [do&lt;br /&gt;&gt;                         x &lt;- arbitrary                   &lt;br /&gt;&gt;                         return (Node x),&lt;br /&gt;&gt;                       do&lt;br /&gt;&gt;                         t &lt;- arbitrary   &lt;br /&gt;&gt;                         t' &lt;- arbitrary   &lt;br /&gt;&gt;                         x &lt;- arbitrary   &lt;br /&gt;&gt;                         return (Branch t x t')]&lt;br /&gt;&lt;br /&gt;&gt;prop_Search t x = dfs x t ==&gt; bfs x t&lt;br /&gt;&lt;/pre&gt;&lt;br /&gt;So here we've defined an instance of the &lt;tt&gt;Arbitrary&lt;/tt&gt; type for our binary tree, and the property we check is that if the depth first search for a random element in a randomly generated tree is true then the breadth first search for that same element in that same tree must be true.&lt;br /&gt;&lt;br /&gt;Of course I think we can go a lot further than this when it comes to exploratory programming and testing.  I personally believe that a very strong static type system can help create a very tidy embedded language for genetic programming, but all I have are some very old toy examples on that front.  Who knows how well we can do if we invoke Conor's Law?&lt;div class="blogger-post-footer"&gt;&lt;img width='1' height='1' src='https://blogger.googleusercontent.com/tracker/2615156186192493130-8640248175803711548?l=abstractabsurd.blogspot.com' alt='' /&gt;&lt;/div&gt;</content><link rel='replies' type='application/atom+xml' href='http://abstractabsurd.blogspot.com/feeds/8640248175803711548/comments/default' title='Post Comments'/><link rel='replies' type='text/html' href='http://www.blogger.com/comment.g?blogID=2615156186192493130&amp;postID=8640248175803711548' title='4 Comments'/><link rel='edit' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/8640248175803711548'/><link rel='self' type='application/atom+xml' href='http://www.blogger.com/feeds/2615156186192493130/posts/default/8640248175803711548'/><link rel='alternate' type='text/html' href='http://abstractabsurd.blogspot.com/2007/02/sussman-robustness-quickcheck.html' title='Sussman, Robustness, &amp; Quickcheck'/><author><name>Creighton Hogg</name><uri>http://www.blogger.com/profile/09820771070038676909</uri><email>noreply@blogger.com</email><gd:image rel='http://schemas.google.com/g/2005#thumbnail' width='16' height='16' src='http://img2.blogblog.com/img/b16-rounded.gif'/></author><thr:total>4</thr:total></entry></feed>
