adjacents :: [(Rank,Int)] -> [(Rank,Rank,Int)]
adjacents rm = foldr f [] rm
  where
  f (r,i) = loop (r,i)
  loop (r,i) im = case im of
    [] -> [(r,r,i)]
    (l,h,i') : rest
      | r == pred l -> (r,h,i * i') : rest
      | r == succ h -> (l,r,i * i') : rest
      | otherwise   -> (l,h,i) : loop (r,i) rest

-- }}}

-- Pairs {{{
adjacents :: [(Rank,Int)] -> [(Rank,Rank,Int)]
adjacents rm = foldr f [] rm
  where
  f (r,i) = loop (r,i)
  loop (r,i) im = case im of
    [] -> [(r,r,i)]
    (l,h,i') : rest
      | r == pred l -> (r,h,i * i') : rest
      | r == succ h -> (l,r,i * i') : rest
      | otherwise   -> (l,h,i) : loop (r,i) rest

-- }}}

-- Pairs {{{
adjacents rm = foldr f [] rm
  where
  f (r,i) = loop (r,i)
  loop (r,i) im = case im of
    [] -> [(r,r,i)]
    (l,h,i') : rest
      | r == pred l -> (r,h,i * i') : rest
      | r == succ h -> (l,r,i * i') : rest
      | otherwise   -> (l,h,i) : loop (r,i) rest

-- }}}

-- Pairs {{{