never executed always true always false
    1 {-# language CPP #-}
    2 {-# language MultiParamTypeClasses #-}
    3 
    4 #ifndef ENABLE_INTERNAL_DOCUMENTATION
    5 {-# OPTIONS_HADDOCK hide #-}
    6 #endif
    7 
    8 module OpenCV.Internal.Core.Types.Vec
    9     ( Vec(..)
   10     , VecDim
   11     , IsVec(..)
   12     ) where
   13 
   14 import "base" Foreign.ForeignPtr ( ForeignPtr, withForeignPtr )
   15 import "base" GHC.TypeLits
   16 import "linear" Linear ( V2, V3, V4 )
   17 import "this" OpenCV.Internal.C.Types
   18 
   19 --------------------------------------------------------------------------------
   20 
   21 newtype Vec (dim :: Nat) (depth :: *)
   22       = Vec {unVec :: ForeignPtr (C'Vec dim depth)}
   23 
   24 type instance C (Vec dim depth) = C'Vec dim depth
   25 
   26 instance WithPtr (Vec dim depth) where
   27     withPtr = withForeignPtr . unVec
   28 
   29 type family VecDim (v :: * -> *) :: Nat
   30 
   31 type instance VecDim (Vec dim) = dim
   32 
   33 type instance VecDim V2 = 2
   34 type instance VecDim V3 = 3
   35 type instance VecDim V4 = 4
   36 
   37 class IsVec (v :: * -> *) (depth :: *)  where
   38     toVec   :: v depth -> Vec (VecDim v) depth
   39     fromVec :: Vec (VecDim v) depth -> v depth
   40 
   41     toVecIO :: v depth -> IO (Vec (VecDim v) depth)
   42     toVecIO = pure . toVec
   43 
   44 --------------------------------------------------------------------------------
   45 
   46 instance (IsVec V2 a, Show a)
   47       => Show (Vec 2 a) where
   48     showsPrec prec vec =
   49         showParen (prec >= 10)
   50         $ showString "toVec "
   51         . showParen True (shows v2)
   52       where
   53         v2 :: V2 a
   54         v2 = fromVec vec
   55 
   56 instance (IsVec V3 a, Show a)
   57       => Show (Vec 3 a) where
   58     showsPrec prec vec =
   59         showParen (prec >= 10)
   60         $ showString "toVec "
   61         . showParen True (shows v3)
   62       where
   63         v3 :: V3 a
   64         v3 = fromVec vec
   65 
   66 instance (IsVec V4 a, Show a)
   67       => Show (Vec 4 a) where
   68     showsPrec prec vec =
   69         showParen (prec >= 10)
   70         $ showString "toVec "
   71         . showParen True (shows v4)
   72       where
   73         v4 :: V4 a
   74         v4 = fromVec vec