Entries in the ‘Software Development’ Category:

Haskell Life With Repa Part 2: Parsing Framework

Conway's Life - Gunstar

Life Pattern - Gunstar

In the last post, we built a simulator for Conway’s Life in Haskell using repa and OpenGL. The initial life pattern in that implementation was hard coded. In this post, I’ll build a framework for parsing patterns from files.

Read the rest…

Tags: , ,

Comments (1)

Conway’s Life in Haskell with Repa and OpenGL

Conway's Life in Haskell

The final state after starting with the acorn pattern

Repa is a new library in Haskell for handling arrays. It has flexible indexing like the old array library, but supports parallel computation, stream fusion, and has a rich API like the vector library.

To learn how to use repa, I implemented Conway’s Life using repa for the simulation and OpenGL for the display. The complete code is available on BitBucket and builds on my GLFW-b boilterplate, so I’ll only discuss the interesting parts here. Don Stewart wrote a good introductory tutorial to repa that will fill in any gaps I leave in this post.

Read the rest…

Tags: , , , ,

Comments (1)

OpenGL in Haskell: GLFW-b Boilerplate

Haskell is turning out to be a great match for OpenGL. Since we can offload a lot of the rendering to shader code, we can use mostly pure Haskell functions to update the game or simulation in response to user input. Over a few blog posts, I’m going to outline how I’ve been using OpenGL in Haskell.

First, to use OpenGL we need a way to open a window, get a context, and respond to user input. There are several different cross-platform libraries to do this, but for simple projects I prefer GLFW. The Haskell package GLFW-b has bindings for GLFW and exposes a more Haskellish API than the regular GLFW package. Read the rest…

Tags: , ,

Comments (2)

Specializing Theme Hooks in Custom Drupal 7 Modules

An important feature of Drupal 7 is the clean separation between the structure of elements created by modules and the rendering of those elements by themes. One cool thing is that a module can provide suggestions for the theme hook which should render an element. This gives theme writers an opportunity to override the theme for very specific elements in a module, and provides for more generic fallback themes otherwise.

The theme hook suggestions are lists of increasingly specific keys separated by a double underscore, for example node__mymodule__block5. The first entry, node here, is a top level hook defined by a hook_theme function. When the theme function is called, the theme system will try the most specific hook first, in this example node__mymodule__block5. If that doesn’t exist, it will try the next hook, node__mymodule, and so on until it gets to the top level hook. Themes that implement these specific hooks with template files will replace the underscores with hyphens, so node__mymodule__block5 would be rendered by node--mymodule--block5.tpl.php.

Module developers can set a theme hook suggestion for an element by using the #theme key of a render array. The keys of the render array will have to include any parameters that the top level hook requires. These parameters are defined when the hook is declared. Hooks in Drupal core have their parameters in the Drupal API, and hooks from custom Drupal modules should be documented in the module. Here is a nice list of default theme hooks in Drupal core

Here is an example that creates a list using a theme suggestion derived from the Drupal core hook item_list, getting the elements from some function get_items.

function mymodule_block_view($delta = "")
    $block = array();
    $block["subject"] = t("My Awesome List");
    $block["content"] = array(
        // item_list is the Drupal core theme hook for unordered or ordered lists
        "#theme" => "item_list__mymodule__awesome_list",
        // #type and #items are parameters for the item_list theme
        "#type" => "ul",
        "#items" => get_items(),

    return $block;

Tags: , ,

Leave a Comment

Inside Drupal are All the Stars in the Sky

I have drilled deep into Drupal and come out the other side, dripping with offal and frustration. It is an incredibly powerful framework, with an easy, standard way to modify literally anything in the system at any point during the page flow. Of course, finding the easy way is the hard part, because there are also ten wrong ways to do anything you want to do, and the API reference is written as more of a gentle reminder to the API authors that relegates the uninitiated to swapping war stories in the comments on each page. I still love it, though, especially now that I know the secrets, which I will be sharing here soon.


Leave a Comment