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