Proposal: unify constant functors

wren ng thornton wren at
Fri May 4 02:12:19 CEST 2012

On 5/3/12 7:18 PM, Henning Thielemann wrote:
> On Thu, 3 May 2012, wren ng thornton wrote:
>> I think that Const/Constant should be in base because it's such a
>> primitive thing and used all over the place. Other than that, I was
>> mainly aiming for minimal breakage in resolving the duplication.
> I just wanted to ask, where you need it. I have never used it. How can I
> improve my code with it?

Again, it's primitive for generic programming with polynomial types. I 
often use it to lift types of kind * into types of kind *->* which is 
frequently necessary for generic programming. The code I was working on 
when I noticed the duplication uses it to instantiate a rank-2 
quantifier in order to get rid of an existential type.

> Independent from this question I am concerned with putting so much into
> 'base'. 'transformers' can be updated independent from the compiler, and
> 'base' cannot. Thus for me, 'Constant' in 'transformers' has the right
> name (understandable to the casual user) in the right place.

Since transformers is in the Haskell Platform, it doesn't especially 
matter to me. But this is the sort of thing that belongs in an extended 
prelude, much like Data.List and other modules from before the era of 
hierarchical module names. The code for the constant functor isn't 
liable to change by much, the only reason for it to change would be to 
add new instances for new classes in base (since other classes could 
provide the instance when defining the class itself), so the fact that 
it's in a boot library isn't much of a burden. Whether GHC actually uses 
it internally may settle the matter, however.

Even the casual user will recognize Const as a capitalized version of 
the const function from the Prelude.

Live well,

More information about the Libraries mailing list