Skip to content

Commit

Permalink
Use a local version of Identity on old versions of base
Browse files Browse the repository at this point in the history
  • Loading branch information
gereeter committed Sep 13, 2016
1 parent c7f8361 commit 8a35111
Showing 1 changed file with 33 additions and 2 deletions.
35 changes: 33 additions & 2 deletions Data/IntMap/Merge/Internal.hs
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
{-# LANGUAGE BangPatterns #-}
{-# LANGUAGE CPP, BangPatterns #-}

#include "containers.h"

-----------------------------------------------------------------------------
-- |
Expand Down Expand Up @@ -30,10 +32,39 @@
module Data.IntMap.Merge.Internal where

import Prelude hiding (min, max)
import Data.Functor.Identity (Identity, runIdentity)

import Data.IntMap.Internal

#if MIN_VERSION_base (4,8,0)
import Data.Functor.Identity (Identity, runIdentity)
#else
import Control.Applicative (Applicative(..))
#if __GLASGOW_HASKELL__ >= 708
import Data.Coerce
#endif
#endif


#if !MIN_VERSION_base (4,8,0)
-- | The identity type.
newtype Identity a = Identity { runIdentity :: a }

#if __GLASGOW_HASKELL__ >= 708
instance Functor Identity where
fmap = coerce
instance Applicative Identity where
(<*>) = coerce
pure = Identity
#else
instance Functor Identity where
fmap f (Identity a) = Identity (f a)
instance Applicative Identity where
Identity f <*> Identity x = Identity (f x)
pure = Identity
#endif
#endif


-- | A tactic for dealing with keys present in one map but not the other in
-- 'merge' or 'mergeA'.
--
Expand Down

0 comments on commit 8a35111

Please sign in to comment.