[haskell-gnuplot] histogram

Henning Thielemann lemming at henning-thielemann.de
Fri May 27 07:05:43 BST 2011

On Thu, 26 May 2011, Michael Litchard wrote:

> From what I understand, the following question is basic Haskell. I'm
> not getting it and I hope I can get clarification here.
> Let's start with newtype T.
> newtype T x y a = Cons String
> This looks like a partially applied type constructor. Is this right?

In this definition everything is fully applied, both the type constructor 
T and the data constructor Cons. That the type parameters 'x', 'y', 'a' on 
the left hand side are not used on the right hand side, is called "phantom 

> Take for example
> lines          :: (Atom.C x, Atom.C y) => T x y (x,y)
> compared with
> histogram :: (Atom.C x) => Graph2DType.T Int Int (x,String)
> The first thing that strikes me is while the variables in lines are
> general ( x or y) the ones in histogram are not. This is where my
> attempt falls apart.

In (T x y a), the 'x' is the type of the values on the x axis, 'y' is the 
type of the values on the y axis and 'a' is the type of the plotted data. 
I thought that histogram data is discrete and thus chose Int as types for 
the axes.

> I'm referencing LYAH in an attempt to grasp this concept, and I feel I
> should have already.
> Could you explain the relationship between newtype T x y a = Cons
> String and histogram :: (Atom.C x) => Graph2DType.T Int Int
> (x,String)?

In the end 'lines' is just mapped to the word "lines" in the gnuplot 
script (curve.gp). But the 'lines' graph type of gnuplot requires a 
certain number and types of columns. This is what I express with the type 
"Graph2DType.T x y (x,y)". It means: X and Y axes may have different type, 
say Int and Float, and the actual data has two columns, one of the type of 
the X axis and one of the type of Y axis. (Atom.C x) restricts the choice 
of types to those that are supported by gnuplot in one column. That is, 
'x' cannot be e.g. (Double,Double) or (IO String).

More information about the Gnuplot mailing list