Personal tools

Context alias

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
(initial version)
 
(additions of things to have in mind)
Line 8: Line 8:
   
 
=== Improvements ===
 
=== Improvements ===
  +
  +
==== “Context alias” instead of “class alias” ====
   
 
A “class alias” actually doesn’t stand for a class but for a context (or a part of a context). So it might be better to choose a slightly different syntax:
 
A “class alias” actually doesn’t stand for a class but for a context (or a part of a context). So it might be better to choose a slightly different syntax:
   
 
context Foobar a = (Foo a, Bar a)
 
context Foobar a = (Foo a, Bar a)
  +
  +
==== Superclass constraints ====
   
 
John Meacham proposes the following syntax for class aliases (context aliases) with superclass constraints:
 
John Meacham proposes the following syntax for class aliases (context aliases) with superclass constraints:
Line 24: Line 28:
   
 
context Eq a => Num a = (Additive a, Multiplicative a)
 
context Eq a => Num a = (Additive a, Multiplicative a)
  +
  +
==== Things to have in mind ====
  +
  +
In order to get the context alias extension well, we should have an eye on problems we might want to solve with the help of context aliases. Here are some:
  +
  +
* <hask>MonadPlus</hask> should just be a combination of <hask>Alternative</hask> and <hask>Monad</hask> (actually, <hask>Alternative f</hask> should just be a combination of <hask>Applicative f</hask> and <hask>forall a. Monoid (f a)</hask>)
  +
  +
* <hask>Applicative</hask> should be a superclass of <hask>Monad</hask>
   
 
== Implementation ==
 
== Implementation ==

Revision as of 12:22, 16 March 2009

Context aliases, also known as class aliases, are a long-requested feature of Haskell. This feature would allow class hierarchies to be restructured without breaking compatibility to a certain degree. Also, it would make fine-grained class hierarchies usable.

Contents

1 The proposal

1.1 The original class alias proposal

The original proposal can be found on a page on John Meachem’s website.

1.2 Improvements

1.2.1 “Context alias” instead of “class alias”

A “class alias” actually doesn’t stand for a class but for a context (or a part of a context). So it might be better to choose a slightly different syntax:

context Foobar a = (Foo a, Bar a)

1.2.2 Superclass constraints

John Meacham proposes the following syntax for class aliases (context aliases) with superclass constraints:

class alias Num a = Eq a => (Additive a, Multiplicative a)

This is not consistent with the superclass syntax of class declarations. I think, we should use this syntax:

class alias Eq a => Num a = (Additive a, Multiplicative a)

Or better:

context Eq a => Num a = (Additive a, Multiplicative a)

1.2.3 Things to have in mind

In order to get the context alias extension well, we should have an eye on problems we might want to solve with the help of context aliases. Here are some:

  • MonadPlus
    should just be a combination of
    Alternative
    and
    Monad
    (actually,
    Alternative f
    should just be a combination of
    Applicative f
    and
    forall a. Monoid (f a)
    )
  • Applicative
    should be a superclass of
    Monad

2 Implementation

Starting an implementation of context aliases is planned for the 5th Haskell Hackathon.