summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSimon Jakobi <simon.jakobi@gmail.com>2019-05-30 00:16:09 +0200
committerMarge Bot <ben+marge-bot@smart-cactus.org>2019-05-31 02:01:55 -0400
commit0c6f7f7eb94f80d3ed74a382af8a3294d070e740 (patch)
tree2f8e3a0be12e39704ff2a7f4a7eee3997919e2a4
parente32786dfc9290e037f70cd942d5922217f2ab7cc (diff)
downloadhaskell-0c6f7f7eb94f80d3ed74a382af8a3294d070e740.tar.gz
Implement (Functor.<$) for Array
-rw-r--r--libraries/base/GHC/Arr.hs9
1 files changed, 9 insertions, 0 deletions
diff --git a/libraries/base/GHC/Arr.hs b/libraries/base/GHC/Arr.hs
index cc0397ec07..730f2205b5 100644
--- a/libraries/base/GHC/Arr.hs
+++ b/libraries/base/GHC/Arr.hs
@@ -848,6 +848,15 @@ cmpIntArray arr1@(Array l1 u1 n1 _) arr2@(Array l2 u2 n2 _) =
instance Functor (Array i) where
fmap = amap
+ {-# INLINE (<$) #-}
+ x <$ Array l u n@(I# n#) _ =
+ -- Sadly we can't just use 'newSTArray' (with 'unsafeFreezeSTArray')
+ -- since that would require proof that the indices of the original array
+ -- are instances of 'Ix'.
+ runST $ ST $ \s1# ->
+ case newArray# n# x s1# of
+ (# s2#, marr# #) -> done l u n marr# s2#
+
-- | @since 2.01
instance (Ix i, Eq e) => Eq (Array i e) where
(==) = eqArray