mergeToks :: (Ord t) => [Token t] -> Token t
mergeToks toks =
  (head toks) {interps = newInterps}
  where
    newInterps =
      [ Interp
        { base = base
        , msd  = msd
        , choice = choice }
      | (msd, (choice, base)) <- M.toList interpsMap ]
    interpsMap = M.fromListWith orBase
      [ (msd, (choice, base))
      | Interp{..} <- concatMap interps toks ]
    -- differences on base values are ignored
    orBase (choice1, base1) (choice2, _base2) = (choice1 || choice2, base1)
mergeToks :: (Ord t) => [Token t] -> Token t
mergeToks toks =
  (head toks) {interps = newInterps}
  where
    newInterps =
      [ Interp
        { base = base
        , msd  = msd
        , choice = choice }
      | (msd, (choice, base)) <- M.toList interpsMap ]
    interpsMap = M.fromListWith orBase
      [ (msd, (choice, base))
      | Interp{..} <- concatMap interps toks ]
    -- differences on base values are ignored
    orBase (choice1, base1) (choice2, _base2) = (choice1 || choice2, base1)
mergeToks toks =
  (head toks) {interps = newInterps}
  where
    newInterps =
      [ Interp
        { base = base
        , msd  = msd
        , choice = choice }
      | (msd, (choice, base)) <- M.toList interpsMap ]
    interpsMap = M.fromListWith orBase
      [ (msd, (choice, base))
      | Interp{..} <- concatMap interps toks ]
    -- differences on base values are ignored
    orBase (choice1, base1) (choice2, _base2) = (choice1 || choice2, base1)