{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE TypeSynonymInstances #-}
module HaskellWorks.Data.Positioning
( Count
, Position
, lastPositionOf
, toCount
, toPosition
) where
import Data.Int
import Data.Word
type Count = Word64
type Position = Int64
class ToPosition a where
toPosition :: a -> Position
instance ToPosition Count where
toPosition = fromIntegral
{-# INLINE toPosition #-}
class ToCount a where
toCount :: a -> Count
instance ToCount Position where
toCount = fromIntegral
{-# INLINE toCount #-}
lastPositionOf :: Count -> Position
lastPositionOf c = fromIntegral c - 1
{-# INLINE lastPositionOf #-}