> {-# LANGUAGE TemplateHaskell, UndecidableInstances, FlexibleInstances, GeneralizedNewtypeDeriving, MultiParamTypeClasses, DeriveDataTypeable, TypeFamilies #-}
> module Types 
>     ( Beep(..) -- ^ re-exported from Types_000
>     , Foo(..)  -- ^ extended here
>     ) where

> import HAppS.Data

<p>We import the old <kbd>Types_000</kbd> qualified as <code>T0</code> to avoid name clashes.</p>

> import qualified Types_000 as T0

<p>Since we are only modifying Foo, we can import and re-export the old version of Beep unmodified (also see the module export list above):</p>

> import           Types_000 (Beep)

<p> Then we extend <code>Foo</code> with the new constructor <code>Bop Int</code>:</p>
>
> $(deriveAll [''Eq,''Ord,''Read,''Show, ''Default]
>  [d|
>      data Foo 
>          = Bar String
>          | Baz Beep
>          | Bop Int
>    |])

<p>Next we create a <code>Version</code> instance which indicates that the previous version of <code>Foo</code> is <code>T0.Foo</code>.</p>

>
> instance Version Foo where
>     mode = extension 1 (Proxy :: Proxy T0.Foo)
>
> $(deriveSerialize ''Foo)
>

<p>And, finally, we specify how to migrate the old data:</p>

> instance Migrate T0.Foo Foo where
>     migrate (T0.Bar str)  = Bar str
>     migrate (T0.Baz beep) = Baz beep

<p>Note that <code>Foo</code> in <kbd>Types.lhs</kbd> and <code>Foo</code> in <kbd>Types_000.lhs</kbd> are different types, namely <code>Types.Foo</code> and <code>Types_000.Foo</code>. So this works for the same reason that renaming <code>Beep</code> to <code>OldBeep</code> works.</p>



