[Haskell-cafe] Of types and constructors; a question of programming style

Scott Turner p.turner at computer.org
Tue Jul 6 10:23:17 EDT 2004

On 2004 July 06 Tuesday 05:35, Graham Klyne wrote:
> When I'm designing datatypes for a Haskell program, I sometimes seem to end
> up with a slightly incoherent mixture of algebraic types and
> constructors. 

> example 

> data Event = Document DocURI Element
>             | Element Name BaseURI Language Children Attributes LiIndex
>             | Subject EndElement
>             | Attribute Name AttributeVal
>             | Text TextVal

At first I was going to say that I would _never_ feel the need to turn a set 
of constructors into a set of types. But looking again at your example 
constructors I grasp what you mean by "incoherent".  In such cases, what may 
help is to consider why such disparate entities would be grouped together.  

It is not uncommon that the reason is that they all are processed by one or a 
few functions. Then you can consider making those functions into a class.  
Whether this is desirable depends on whether splitting up the implementation 
of the original functions, reorganized by "type", makes the program more 

More information about the Haskell-Cafe mailing list