[Haskell-cafe] Deprecation cycle for classes

Tom Ellis tom-lists-haskell-cafe-2017 at jaguarpaw.co.uk
Sat Jun 15 16:20:26 UTC 2019


I am unsure how to change the name of a class in a library whilst providing
a safe deprecation cycle for the users of the library.  Suppose I have
version 1 of my library with a class

    -- Version 1
    class Foo a where
        foo :: a

and I want to migrate it to version 3 as follows, but with a deprecation
cycle provided by version 2 that allows code to work with either version 1
and 2, or 2 and 3.

    -- Version 3
    class Bar a where
        bar :: a

Then I can try to write version 2 as

    -- Version 2
    {-# ConstraintKinds #-}

    class Foo a where
        bar :: a
        bar = foo
        foo :: a
        foo = bar
    
    type Bar = Foo

This satisfies the following conditions:

Users of versions 1 and 2 can use

* The constraint Foo
* The method foo
* The class Foo and method foo for implementing their own instances

User of versions 2 and 3 can use

* The constraint Bar
* The method bar
* The method bar for implementing their own instances

but they cannot jointly use

* The *class* Bar for implementing their own instances

(since Bar is not a class, just a Constraint)

Is there any way I can write a version 2 that allows users to implement
instances that work with both version 2 and version 3?

Thanks,

Tom


More information about the Haskell-Cafe mailing list