Book Image

Haskell Data Analysis cookbook

By : Nishant Shukla
Book Image

Haskell Data Analysis cookbook

By: Nishant Shukla

Overview of this book

Step-by-step recipes filled with practical code samples and engaging examples demonstrate Haskell in practice, and then the concepts behind the code. This book shows functional developers and analysts how to leverage their existing knowledge of Haskell specifically for high-quality data analysis. A good understanding of data sets and functional programming is assumed.
Table of Contents (14 chapters)
13
Index

Working with hexagonal and square grid networks


Sometimes, the graph we're dealing with has a strict structure, such as a hexagonal or square grid. Many video games use a hexagonal grid layout to facilitate diagonal movement because moving diagonally in a square grid complicates the values of the traveled distance. On the other hand, square grid structures are often used within graphs to traverse pixels for image manipulation algorithms such as flood fill.

There is a very useful library in the Haskell package listing to deal with such topologies. We can obtain the indices of a grid to traverse the world, which is essentially a path embedded in a graph. For each grid index, we can query the library to find the neighboring indices, effectively using grids as a graph.

Getting started

Review the package documentation located at https://github.com/mhwombat/grid/wiki.

Install the grid package using cabal:

$ cabal install grid

How to do it...

In a new file, which we will name Main.hs, insert the following...