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

Diagramming a path from a list of vectors

In this recipe, we will use the diagrams package to draw a path from driving directions. We simply categorize all possible travel headings into eight cardinal directions with an associated distance. We use directions provided by Google Maps in the following screenshot and reconstruct the directions from a text file:

Diagramming a path from a list of vectors

Getting ready

Install the diagrams library as follows:

$ cabal install diagrams

Create a text file called input.txt that contains one of the eight cardinal directions followed by the distance, with each step separated by a new line:

$ cat input.txt

N 0.2
W 0.1
S 0.6
W 0.05
S 0.3
SW 0.1
SW 0.2
SW 0.3
S 0.3

How to do it…

  1. Import the relevant libraries as follows:
    {-# LANGUAGE NoMonomorphismRestriction #-}
    import Diagrams.Prelude
    import Diagrams.Backend.SVG.CmdLine (mainWith, B)
  2. Draw a line-connected path from a list of vectors as follows:
    drawPath :: [(Double, Double)] -> Diagram B R2
    drawPath vectors = fromOffsets . map r2 $ vectors...