{- | replace all occurrences of the first (non-empty sublist) argument
     with the second argument in the third (list) argument. -}
replace :: Eq a => [a] -> [a] -> [a] -> [a]
replace sl r = case sl of
  [] -> error "Common.Utils.replace: empty list"
  _ -> concat . unfoldr (\ l -> case l of
    [] -> Nothing
    hd : tl -> Just $ case stripPrefix sl l of
      Nothing -> ([hd], tl)
      Just rt -> (r, rt))

-- | add indices to a list starting from one
replace :: Eq a => [a] -> [a] -> [a] -> [a]
replace sl r = case sl of
  [] -> error "Common.Utils.replace: empty list"
  _ -> concat . unfoldr (\ l -> case l of
    [] -> Nothing
    hd : tl -> Just $ case stripPrefix sl l of
      Nothing -> ([hd], tl)
      Just rt -> (r, rt))

-- | add indices to a list starting from one
replace sl r = case sl of
  [] -> error "Common.Utils.replace: empty list"
  _ -> concat . unfoldr (\ l -> case l of
    [] -> Nothing
    hd : tl -> Just $ case stripPrefix sl l of
      Nothing -> ([hd], tl)
      Just rt -> (r, rt))

-- | add indices to a list starting from one