ConstPtr compatibility

Is there a compatibility package for ConstPtr? I don’t want to limit my FFI bindings to >= base-4.18 when without ConstPtr that boundary would be around >= base-4.9.

The solution I’ve been using is this CPP override, and it’s both ugly, not properly compatible across versions, and not something I would want to use as a potential “import statement” in a templater.

#if MIN_VERSION_base (4,18,0)
import           Foreign.C.ConstPtr
#else
##define ConstPtr Ptr
#endif

Consider me interested in this as well - at current I’ve been using the following shim:

#if MIN_VERSION_base (4,18,0)
import Foreign.C.ConstPtr
#else
import Data.Data
import Data.Kind
#endif

#if !(MIN_VERSION_base (4,18,0))

-- NOTE: Taken from Foreign.C.ConstPtr, more or less
-- NOTE: Raises a warning on older base / compilers if the shim
--       is a `newtype` instead of a `type`, because the special
--       logic for const pointers didn't exist yet
-- SEE: https://gitlab.haskell.org/ghc/ghc/-/issues/22043
type ConstPtr :: Type -> Type
type role ConstPtr phantom
newtype ConstPtr a = ConstPtr { unConstPtr :: Ptr a }
    deriving stock (Data)
    deriving newtype (Eq, Ord, Storable)

instance Show (ConstPtr a) where
    showsPrec d (ConstPtr p) = showParen (d > 10) $ showString "ConstPtr " . showsPrec 11 p

#endif

If there were a better / proper solution, I’d switch to that.