summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorparsonsmatt <parsonsmatt@gmail.com>2023-01-03 11:25:41 -0700
committerMarge Bot <ben+marge-bot@smart-cactus.org>2023-02-10 09:53:11 -0500
commit59556235a8d216b6274ad7966b70b585f585cdaa (patch)
tree9324a84bf922745ec23b95ebe2d2e8f5b4df6149
parent11e0cacb039cee4198cd6043ab0d9e08332d4d8a (diff)
downloadhaskell-59556235a8d216b6274ad7966b70b585f585cdaa.tar.gz
Add Lift instance for Fixed
-rw-r--r--libraries/template-haskell/Language/Haskell/TH/Syntax.hs10
-rw-r--r--libraries/template-haskell/changelog.md1
2 files changed, 11 insertions, 0 deletions
diff --git a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
index 0304eb130b..8be340bf93 100644
--- a/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
+++ b/libraries/template-haskell/Language/Haskell/TH/Syntax.hs
@@ -31,6 +31,7 @@ module Language.Haskell.TH.Syntax
-- $infix
) where
+import qualified Data.Fixed as Fixed
import Data.Data hiding (Fixity(..))
import Data.IORef
import System.IO.Unsafe ( unsafePerformIO )
@@ -1056,6 +1057,15 @@ instance Lift Natural where
liftTyped x = unsafeCodeCoerce (lift x)
lift x = return (LitE (IntegerL (fromIntegral x)))
+instance Lift (Fixed.Fixed a) where
+ liftTyped x = unsafeCodeCoerce (lift x)
+ lift (Fixed.MkFixed x) = do
+ ex <- lift x
+ return (ConE mkFixedName `AppE` ex)
+ where
+ mkFixedName =
+ mkNameG DataName "base" "Data.Fixed" "MkFixed"
+
instance Integral a => Lift (Ratio a) where
liftTyped x = unsafeCodeCoerce (lift x)
lift x = return (LitE (RationalL (toRational x)))
diff --git a/libraries/template-haskell/changelog.md b/libraries/template-haskell/changelog.md
index bf63b6e689..8382efd1fc 100644
--- a/libraries/template-haskell/changelog.md
+++ b/libraries/template-haskell/changelog.md
@@ -7,6 +7,7 @@
* Add `TypeDataD` constructor to the `Dec` type for `type data`
declarations (GHC proposal #106).
+ * Add `instance Lift (Fixed a)`
## 2.19.0.0