{-# LANGUAGE NamedFieldPuns #-}
{-# LANGUAGE RecordWildCards #-}
module LiveCoding.Migrate.Debugger where
import Control.Monad (guard)
import Data.Data
import Data.Maybe
import LiveCoding.Debugger
import LiveCoding.Migrate.Migration
migrateToDebugging
:: Debugging dbgState state
-> state
-> Debugging dbgState state
migrateToDebugging Debugging { dbgState } state = Debugging { .. }
migrationToDebugging :: Migration
migrationToDebugging = Migration $ \a b -> do
guard $ ("Debugging" ==) $ dataTypeName $ dataTypeOf a
gmapMo (const $ cast b) a
migrationFromDebugging :: Migration
migrationFromDebugging = Migration $ \_ b -> do
guard $ ("Debugging" ==) $ dataTypeName $ dataTypeOf b
listToMaybe $ catMaybes $ (gmapQ cast) b
migrateFromDebugging
:: state
-> Debugging dbgState state
-> state
migrateFromDebugging _state Debugging { state } = state
migrationDebugging :: Migration
migrationDebugging = migrationToDebugging <> migrationFromDebugging