diff options
Diffstat (limited to 'compiler/utils')
-rw-r--r-- | compiler/utils/Util.hs | 8 |
1 files changed, 8 insertions, 0 deletions
diff --git a/compiler/utils/Util.hs b/compiler/utils/Util.hs index 5f66b53171..3104c747a1 100644 --- a/compiler/utils/Util.hs +++ b/compiler/utils/Util.hs @@ -47,6 +47,8 @@ module Util ( chunkList, + changeLast, + -- * Tuples fstOf3, sndOf3, thdOf3, firstM, first3M, @@ -571,6 +573,12 @@ chunkList :: Int -> [a] -> [[a]] chunkList _ [] = [] chunkList n xs = as : chunkList n bs where (as,bs) = splitAt n xs +-- | Replace the last element of a list with another element. +changeLast :: [a] -> a -> [a] +changeLast [] _ = panic "changeLast" +changeLast [_] x = [x] +changeLast (x:xs) x' = x : changeLast xs x' + {- ************************************************************************ * * |