Skip to content

Instantly share code, notes, and snippets.

@teh
Last active August 29, 2015 14:17
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save teh/859ac2a7df0ac33428d1 to your computer and use it in GitHub Desktop.
Save teh/859ac2a7df0ac33428d1 to your computer and use it in GitHub Desktop.

Backwards compatible configuration

If some record can change it's a good idea to use a sum type, e.g. you start out with your new program like this:

data Wibble = WibbleV0 { port :: Int, name :: String }

A year later you have a new feature that requires more info. Now you can add:

data Wibble = WibbleV0 { port :: Int, name :: String }
            | WibbleV1 { port :: Int, name :: String, isAwesome :: Bool }

This has the advantage that you can now create a WibbleV1 from a WibbleV0 with some sensible default behaviour, and then use WibbleV1 internally everywhere.

Another nice feature is that you can warn users of your library that the config interface has changed:

{-# DEPRECATED WibbleV0 "WibbleV0 is deprecated, use WibbleV1" #-}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment