{-# OPTIONS_HADDOCK hide #-}
-- |
--
-- Module      : Raaz.Core.Types.Copying
-- Description : Avoid confusion between source and destination while copying.
-- Copyright   : (c) Piyush P Kurur, 2016
-- License     : Apache-2.0 OR BSD-3-Clause
-- Maintainer  : Piyush P Kurur <ppk@iitpkd.ac.in>
-- Stability   : experimental
--
module Raaz.Core.Types.Copying
       ( Src(..), Dest(..), source, destination
       ) where

import Raaz.Core.Prelude

-- | The source of a copy operation. Besides the `source` smart
-- constructor, the functor instance allows to transform the internal
-- type using the `fmap` (e.g. given an @sptr :: Src (Ptr Word8)@
-- shift it by an offset).
--
-- For FFI use: One can use this type directly in FFI interface by
-- importing "Raaz.Core.Types.Internal" to get access to the
-- constructor.
newtype Src  a = Src { Src a -> a
unSrc :: a }

-- | Smart constructor for `Src`. Copying functions
source :: a -> Src a
source :: a -> Src a
source = a -> Src a
forall a. a -> Src a
Src

instance Functor Src where
  fmap :: (a -> b) -> Src a -> Src b
fmap a -> b
f = b -> Src b
forall a. a -> Src a
Src (b -> Src b) -> (Src a -> b) -> Src a -> Src b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f (a -> b) -> (Src a -> a) -> Src a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Src a -> a
forall a. Src a -> a
unSrc

-- | The destination of a copy operation. Besides the `destination`
-- smart constructor, the functor instance allows to transform the
-- internal type using the `fmap` (e.g. given an @dptr :: Dest (Ptr
-- Word8)@ shift it by an offset).
--
-- For FFI use: One can use this type directly in FFI interface by
-- importing "Raaz.Core.Types.Internal" to get access to the
-- constructor.

newtype Dest a = Dest { Dest a -> a
unDest :: a }

-- | Smart constructor for `Dest`.
destination :: a -> Dest a
destination :: a -> Dest a
destination = a -> Dest a
forall a. a -> Dest a
Dest

instance Functor Dest where
  fmap :: (a -> b) -> Dest a -> Dest b
fmap a -> b
f = b -> Dest b
forall a. a -> Dest a
Dest (b -> Dest b) -> (Dest a -> b) -> Dest a -> Dest b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. a -> b
f (a -> b) -> (Dest a -> a) -> Dest a -> b
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Dest a -> a
forall a. Dest a -> a
unDest