summaryrefslogtreecommitdiff
path: root/compiler/utils/Util.hs
diff options
context:
space:
mode:
authorRyan Scott <ryan.gl.scott@gmail.com>2016-11-06 09:09:36 -0500
committerRyan Scott <ryan.gl.scott@gmail.com>2016-11-06 09:09:36 -0500
commit630d88176e8dd3ccc269451bca8f55398ef5265c (patch)
tree71660e73c5e770ee83a1bbad4452a0d23e20f42a /compiler/utils/Util.hs
parent25c8e80eccc512d05c0ca8df401271db65b5987b (diff)
downloadhaskell-630d88176e8dd3ccc269451bca8f55398ef5265c.tar.gz
Allow GeneralizedNewtypeDeriving for classes with associated type families
Summary: This implements the ability to derive associated type family instances for newtypes automatically using `GeneralizedNewtypeDeriving`. Refer to the users' guide additions for how this works; I essentially follow the pattern laid out in https://ghc.haskell.org/trac/ghc/ticket/8165#comment:18. Fixes #2721 and #8165. Test Plan: ./validate Reviewers: simonpj, goldfire, austin, bgamari Reviewed By: simonpj Subscribers: mpickering, thomie Differential Revision: https://phabricator.haskell.org/D2636 GHC Trac Issues: #2721, #8165
Diffstat (limited to 'compiler/utils/Util.hs')
-rw-r--r--compiler/utils/Util.hs8
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'
+
{-
************************************************************************
* *