module Data.PrimitiveArray.Index.PhantomInt where
import Control.DeepSeq (NFData(..))
import Data.Aeson (FromJSON,ToJSON)
import Data.Binary (Binary)
import Data.Data
import Data.Hashable (Hashable)
import Data.Ix(Ix)
import Data.Serialize (Serialize)
import Data.Typeable
import Data.Vector.Fusion.Stream.Monadic (map,Step(..))
import Data.Vector.Unboxed.Deriving
import GHC.Generics (Generic)
import Prelude hiding (map)
import Data.PrimitiveArray.Index.Class
import Data.PrimitiveArray.Index.IOC
import Data.PrimitiveArray.Vector.Compat
newtype PInt t p = PInt { getPInt :: Int }
deriving (Read,Show,Eq,Ord,Enum,Num,Integral,Real,Generic,Data,Typeable,Ix)
pIntI :: Int -> PInt I p
pIntI = PInt
pIntO :: Int -> PInt O p
pIntO = PInt
pIntC :: Int -> PInt C p
pIntC = PInt
derivingUnbox "PInt"
[t| forall t p . PInt t p -> Int |] [| getPInt |] [| PInt |]
instance Binary (PInt t p)
instance Serialize (PInt t p)
instance FromJSON (PInt t p)
instance ToJSON (PInt t p)
instance Hashable (PInt t p)
instance NFData (PInt t p)
instance Index (PInt t p) where
linearIndex _ _ (PInt k) = k
smallestLinearIndex _ = error "still needed?"
largestLinearIndex (PInt h) = h
size _ (PInt h) = h+1
inBounds l h k = l <= k && k <= h
instance IndexStream z => IndexStream (z:.PInt I p) where
streamUp (ls:.l) (hs:.h) = flatten (streamUpMk l h) (streamUpStep l h) $ streamUp ls hs
streamDown (ls:.l) (hs:.h) = flatten (streamDownMk l h) (streamDownStep l h) $ streamDown ls hs
instance IndexStream z => IndexStream (z:.PInt O p) where
streamUp (ls:.l) (hs:.h) = flatten (streamDownMk l h) (streamDownStep l h) $ streamUp ls hs
streamDown (ls:.l) (hs:.h) = flatten (streamUpMk l h) (streamUpStep l h) $ streamDown ls hs
instance IndexStream z => IndexStream (z:.PInt C p) where
streamUp (ls:.l) (hs:.h) = flatten (streamUpMk l h) (streamUpStep l h) $ streamUp ls hs
streamDown (ls:.l) (hs:.h) = flatten (streamDownMk l h) (streamDownStep l h) $ streamDown ls hs
streamUpMk l h z = return (z,l)
streamUpStep l h (z,k)
| k > h = return $ Done
| otherwise = return $ Yield (z:.k) (z,k+1)
streamDownMk l h z = return (z,h)
streamDownStep l h (z,k)
| k < l = return $ Done
| otherwise = return $ Yield (z:.k) (z,k1)
instance IndexStream (PInt I p)
instance IndexStream (PInt O p)
instance IndexStream (PInt C p)