    {-# LANGUAGE DeriveDataTypeable #-}
    {-# LANGUAGE ScopedTypeVariables #-}
    {-# LANGUAGE ExistentialQuantification #-}
    {-# LANGUAGE GeneralizedNewtypeDeriving #-}
    {-# LANGUAGE MultiParamTypeClasses #-}
    {-# LANGUAGE TemplateHaskell #-}
    {-# LANGUAGE DeriveGeneric #-}
    {-# LANGUAGE CPP #-}

    -- Copyright 2008 JP Bernardy
    -- | Basic types useful everywhere we play with buffers.
    module Yi.Buffer.Basic where

    import Data.Binary
    import Data.Typeable
    import GHC.Generics (Generic)
    import Data.Ix
    import Data.Default
    import Yi.Utils

    -- | Direction of movement inside a buffer
    data Direction = Backward | Forward
        deriving (Direction -> Direction -> Bool
    (Direction -> Direction -> Bool)
    -> (Direction -> Direction -> Bool) -> Eq Direction
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Direction -> Direction -> Bool
    == :: Direction -> Direction -> Bool
    $c/= :: Direction -> Direction -> Bool
    /= :: Direction -> Direction -> Bool
    Eq, Eq Direction
    Eq Direction =>
    (Direction -> Direction -> Ordering)
    -> (Direction -> Direction -> Bool)
    -> (Direction -> Direction -> Bool)
    -> (Direction -> Direction -> Bool)
    -> (Direction -> Direction -> Bool)
    -> (Direction -> Direction -> Direction)
    -> (Direction -> Direction -> Direction)
    -> Ord Direction
    Direction -> Direction -> Bool
    Direction -> Direction -> Ordering
    Direction -> Direction -> Direction
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: Direction -> Direction -> Ordering
    compare :: Direction -> Direction -> Ordering
    $c< :: Direction -> Direction -> Bool
    < :: Direction -> Direction -> Bool
    $c<= :: Direction -> Direction -> Bool
    <= :: Direction -> Direction -> Bool
    $c> :: Direction -> Direction -> Bool
    > :: Direction -> Direction -> Bool
    $c>= :: Direction -> Direction -> Bool
    >= :: Direction -> Direction -> Bool
    $cmax :: Direction -> Direction -> Direction
    max :: Direction -> Direction -> Direction
    $cmin :: Direction -> Direction -> Direction
    min :: Direction -> Direction -> Direction
    Ord, Typeable, Int -> Direction -> ShowS
    [Direction] -> ShowS
    Direction -> String
    (Int -> Direction -> ShowS)
    -> (Direction -> String)
    -> ([Direction] -> ShowS)
    -> Show Direction
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Direction -> ShowS
    showsPrec :: Int -> Direction -> ShowS
    $cshow :: Direction -> String
    show :: Direction -> String
    $cshowList :: [Direction] -> ShowS
    showList :: [Direction] -> ShowS
    Show, Direction
    Direction -> Direction -> Bounded Direction
    forall a. a -> a -> Bounded a
    $cminBound :: Direction
    minBound :: Direction
    $cmaxBound :: Direction
    maxBound :: Direction
    Bounded, Int -> Direction
    Direction -> Int
    Direction -> [Direction]
    Direction -> Direction
    Direction -> Direction -> [Direction]
    Direction -> Direction -> Direction -> [Direction]
    (Direction -> Direction)
    -> (Direction -> Direction)
    -> (Int -> Direction)
    -> (Direction -> Int)
    -> (Direction -> [Direction])
    -> (Direction -> Direction -> [Direction])
    -> (Direction -> Direction -> [Direction])
    -> (Direction -> Direction -> Direction -> [Direction])
    -> Enum Direction
    forall a.
    (a -> a)
    -> (a -> a)
    -> (Int -> a)
    -> (a -> Int)
    -> (a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> a -> [a])
    -> Enum a
    $csucc :: Direction -> Direction
    succ :: Direction -> Direction
    $cpred :: Direction -> Direction
    pred :: Direction -> Direction
    $ctoEnum :: Int -> Direction
    toEnum :: Int -> Direction
    $cfromEnum :: Direction -> Int
    fromEnum :: Direction -> Int
    $cenumFrom :: Direction -> [Direction]
    enumFrom :: Direction -> [Direction]
    $cenumFromThen :: Direction -> Direction -> [Direction]
    enumFromThen :: Direction -> Direction -> [Direction]
    $cenumFromTo :: Direction -> Direction -> [Direction]
    enumFromTo :: Direction -> Direction -> [Direction]
    $cenumFromThenTo :: Direction -> Direction -> Direction -> [Direction]
    enumFromThenTo :: Direction -> Direction -> Direction -> [Direction]
    Enum, (forall x. Direction -> Rep Direction x)
    -> (forall x. Rep Direction x -> Direction) -> Generic Direction
    forall x. Rep Direction x -> Direction
    forall x. Direction -> Rep Direction x
    forall a.
    (forall x. a -> Rep a x) -> (forall x. Rep a x -> a) -> Generic a
    $cfrom :: forall x. Direction -> Rep Direction x
    from :: forall x. Direction -> Rep Direction x
    $cto :: forall x. Rep Direction x -> Direction
    to :: forall x. Rep Direction x -> Direction
    Generic)

    instance Binary Direction

    reverseDir :: Direction -> Direction
    reverseDir :: Direction -> Direction
    reverseDir Direction
    Forward = Direction
    Backward
    reverseDir Direction
    Backward = Direction
    Forward

    -- | reverse if Backward
    mayReverse :: Direction -> [a] -> [a]
    mayReverse :: forall a. Direction -> [a] -> [a]
    mayReverse Direction
    Forward = [a] -> [a]
    forall a. a -> a
    id
    mayReverse Direction
    Backward = [a] -> [a]
    forall a. [a] -> [a]
    reverse

    -- | 'direction' is in the same style of 'maybe' or 'either' functions,
    -- It takes one argument per direction (backward, then forward) and a
    -- direction to select the output.
    directionElim :: Direction -> a -> a -> a
    directionElim :: forall a. Direction -> a -> a -> a
    directionElim Direction
    Backward a
    b a
    _ = a
    b
    directionElim Direction
    Forward  a
    _ a
    f = a
    f

    -- | A mark in a buffer
    newtype Mark = Mark {Mark -> Int
    markId::Int} deriving (Mark -> Mark -> Bool
    (Mark -> Mark -> Bool) -> (Mark -> Mark -> Bool) -> Eq Mark
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Mark -> Mark -> Bool
    == :: Mark -> Mark -> Bool
    $c/= :: Mark -> Mark -> Bool
    /= :: Mark -> Mark -> Bool
    Eq, Eq Mark
    Eq Mark =>
    (Mark -> Mark -> Ordering)
    -> (Mark -> Mark -> Bool)
    -> (Mark -> Mark -> Bool)
    -> (Mark -> Mark -> Bool)
    -> (Mark -> Mark -> Bool)
    -> (Mark -> Mark -> Mark)
    -> (Mark -> Mark -> Mark)
    -> Ord Mark
    Mark -> Mark -> Bool
    Mark -> Mark -> Ordering
    Mark -> Mark -> Mark
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: Mark -> Mark -> Ordering
    compare :: Mark -> Mark -> Ordering
    $c< :: Mark -> Mark -> Bool
    < :: Mark -> Mark -> Bool
    $c<= :: Mark -> Mark -> Bool
    <= :: Mark -> Mark -> Bool
    $c> :: Mark -> Mark -> Bool
    > :: Mark -> Mark -> Bool
    $c>= :: Mark -> Mark -> Bool
    >= :: Mark -> Mark -> Bool
    $cmax :: Mark -> Mark -> Mark
    max :: Mark -> Mark -> Mark
    $cmin :: Mark -> Mark -> Mark
    min :: Mark -> Mark -> Mark
    Ord, Int -> Mark -> ShowS
    [Mark] -> ShowS
    Mark -> String
    (Int -> Mark -> ShowS)
    -> (Mark -> String) -> ([Mark] -> ShowS) -> Show Mark
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Mark -> ShowS
    showsPrec :: Int -> Mark -> ShowS
    $cshow :: Mark -> String
    show :: Mark -> String
    $cshowList :: [Mark] -> ShowS
    showList :: [Mark] -> ShowS
    Show, Typeable, Get Mark
    [Mark] -> Put
    Mark -> Put
    (Mark -> Put) -> Get Mark -> ([Mark] -> Put) -> Binary Mark
    forall t. (t -> Put) -> Get t -> ([t] -> Put) -> Binary t
    $cput :: Mark -> Put
    put :: Mark -> Put
    $cget :: Get Mark
    get :: Get Mark
    $cputList :: [Mark] -> Put
    putList :: [Mark] -> Put
    Binary)

    -- | Reference to a buffer.
    newtype BufferRef = BufferRef Int
        deriving (BufferRef -> BufferRef -> Bool
    (BufferRef -> BufferRef -> Bool)
    -> (BufferRef -> BufferRef -> Bool) -> Eq BufferRef
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: BufferRef -> BufferRef -> Bool
    == :: BufferRef -> BufferRef -> Bool
    $c/= :: BufferRef -> BufferRef -> Bool
    /= :: BufferRef -> BufferRef -> Bool
    Eq, Eq BufferRef
    Eq BufferRef =>
    (BufferRef -> BufferRef -> Ordering)
    -> (BufferRef -> BufferRef -> Bool)
    -> (BufferRef -> BufferRef -> Bool)
    -> (BufferRef -> BufferRef -> Bool)
    -> (BufferRef -> BufferRef -> Bool)
    -> (BufferRef -> BufferRef -> BufferRef)
    -> (BufferRef -> BufferRef -> BufferRef)
    -> Ord BufferRef
    BufferRef -> BufferRef -> Bool
    BufferRef -> BufferRef -> Ordering
    BufferRef -> BufferRef -> BufferRef
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: BufferRef -> BufferRef -> Ordering
    compare :: BufferRef -> BufferRef -> Ordering
    $c< :: BufferRef -> BufferRef -> Bool
    < :: BufferRef -> BufferRef -> Bool
    $c<= :: BufferRef -> BufferRef -> Bool
    <= :: BufferRef -> BufferRef -> Bool
    $c> :: BufferRef -> BufferRef -> Bool
    > :: BufferRef -> BufferRef -> Bool
    $c>= :: BufferRef -> BufferRef -> Bool
    >= :: BufferRef -> BufferRef -> Bool
    $cmax :: BufferRef -> BufferRef -> BufferRef
    max :: BufferRef -> BufferRef -> BufferRef
    $cmin :: BufferRef -> BufferRef -> BufferRef
    min :: BufferRef -> BufferRef -> BufferRef
    Ord, Typeable, Get BufferRef
    [BufferRef] -> Put
    BufferRef -> Put
    (BufferRef -> Put)
    -> Get BufferRef -> ([BufferRef] -> Put) -> Binary BufferRef
    forall t. (t -> Put) -> Get t -> ([t] -> Put) -> Binary t
    $cput :: BufferRef -> Put
    put :: BufferRef -> Put
    $cget :: Get BufferRef
    get :: Get BufferRef
    $cputList :: [BufferRef] -> Put
    putList :: [BufferRef] -> Put
    Binary,
                  Integer -> BufferRef
    BufferRef -> BufferRef
    BufferRef -> BufferRef -> BufferRef
    (BufferRef -> BufferRef -> BufferRef)
    -> (BufferRef -> BufferRef -> BufferRef)
    -> (BufferRef -> BufferRef -> BufferRef)
    -> (BufferRef -> BufferRef)
    -> (BufferRef -> BufferRef)
    -> (BufferRef -> BufferRef)
    -> (Integer -> BufferRef)
    -> Num BufferRef
    forall a.
    (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a)
    -> (a -> a)
    -> (a -> a)
    -> (Integer -> a)
    -> Num a
    $c+ :: BufferRef -> BufferRef -> BufferRef
    + :: BufferRef -> BufferRef -> BufferRef
    $c- :: BufferRef -> BufferRef -> BufferRef
    - :: BufferRef -> BufferRef -> BufferRef
    $c* :: BufferRef -> BufferRef -> BufferRef
    * :: BufferRef -> BufferRef -> BufferRef
    $cnegate :: BufferRef -> BufferRef
    negate :: BufferRef -> BufferRef
    $cabs :: BufferRef -> BufferRef
    abs :: BufferRef -> BufferRef
    $csignum :: BufferRef -> BufferRef
    signum :: BufferRef -> BufferRef
    $cfromInteger :: Integer -> BufferRef
    fromInteger :: Integer -> BufferRef
    Num)

    instance Show BufferRef where
        show :: BufferRef -> String
    show (BufferRef Int
    r) = String
    "B#" String -> ShowS
    forall a. [a] -> [a] -> [a]
    ++ Int -> String
    forall a. Show a => a -> String
    show Int
    r

    -- | A point in a buffer
    newtype Point = Point {Point -> Int
    fromPoint :: Int}           -- offset in the buffer (#codepoints, NOT bytes)
        deriving (Point -> Point -> Bool
    (Point -> Point -> Bool) -> (Point -> Point -> Bool) -> Eq Point
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Point -> Point -> Bool
    == :: Point -> Point -> Bool
    $c/= :: Point -> Point -> Bool
    /= :: Point -> Point -> Bool
    Eq, Eq Point
    Eq Point =>
    (Point -> Point -> Ordering)
    -> (Point -> Point -> Bool)
    -> (Point -> Point -> Bool)
    -> (Point -> Point -> Bool)
    -> (Point -> Point -> Bool)
    -> (Point -> Point -> Point)
    -> (Point -> Point -> Point)
    -> Ord Point
    Point -> Point -> Bool
    Point -> Point -> Ordering
    Point -> Point -> Point
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: Point -> Point -> Ordering
    compare :: Point -> Point -> Ordering
    $c< :: Point -> Point -> Bool
    < :: Point -> Point -> Bool
    $c<= :: Point -> Point -> Bool
    <= :: Point -> Point -> Bool
    $c> :: Point -> Point -> Bool
    > :: Point -> Point -> Bool
    $c>= :: Point -> Point -> Bool
    >= :: Point -> Point -> Bool
    $cmax :: Point -> Point -> Point
    max :: Point -> Point -> Point
    $cmin :: Point -> Point -> Point
    min :: Point -> Point -> Point
    Ord, Int -> Point
    Point -> Int
    Point -> [Point]
    Point -> Point
    Point -> Point -> [Point]
    Point -> Point -> Point -> [Point]
    (Point -> Point)
    -> (Point -> Point)
    -> (Int -> Point)
    -> (Point -> Int)
    -> (Point -> [Point])
    -> (Point -> Point -> [Point])
    -> (Point -> Point -> [Point])
    -> (Point -> Point -> Point -> [Point])
    -> Enum Point
    forall a.
    (a -> a)
    -> (a -> a)
    -> (Int -> a)
    -> (a -> Int)
    -> (a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> a -> [a])
    -> Enum a
    $csucc :: Point -> Point
    succ :: Point -> Point
    $cpred :: Point -> Point
    pred :: Point -> Point
    $ctoEnum :: Int -> Point
    toEnum :: Int -> Point
    $cfromEnum :: Point -> Int
    fromEnum :: Point -> Int
    $cenumFrom :: Point -> [Point]
    enumFrom :: Point -> [Point]
    $cenumFromThen :: Point -> Point -> [Point]
    enumFromThen :: Point -> Point -> [Point]
    $cenumFromTo :: Point -> Point -> [Point]
    enumFromTo :: Point -> Point -> [Point]
    $cenumFromThenTo :: Point -> Point -> Point -> [Point]
    enumFromThenTo :: Point -> Point -> Point -> [Point]
    Enum, Point
    Point -> Point -> Bounded Point
    forall a. a -> a -> Bounded a
    $cminBound :: Point
    minBound :: Point
    $cmaxBound :: Point
    maxBound :: Point
    Bounded, Typeable, Get Point
    [Point] -> Put
    Point -> Put
    (Point -> Put) -> Get Point -> ([Point] -> Put) -> Binary Point
    forall t. (t -> Put) -> Get t -> ([t] -> Put) -> Binary t
    $cput :: Point -> Put
    put :: Point -> Put
    $cget :: Get Point
    get :: Get Point
    $cputList :: [Point] -> Put
    putList :: [Point] -> Put
    Binary, Ord Point
    Ord Point =>
    ((Point, Point) -> [Point])
    -> ((Point, Point) -> Point -> Int)
    -> ((Point, Point) -> Point -> Int)
    -> ((Point, Point) -> Point -> Bool)
    -> ((Point, Point) -> Int)
    -> ((Point, Point) -> Int)
    -> Ix Point
    (Point, Point) -> Int
    (Point, Point) -> [Point]
    (Point, Point) -> Point -> Bool
    (Point, Point) -> Point -> Int
    forall a.
    Ord a =>
    ((a, a) -> [a])
    -> ((a, a) -> a -> Int)
    -> ((a, a) -> a -> Int)
    -> ((a, a) -> a -> Bool)
    -> ((a, a) -> Int)
    -> ((a, a) -> Int)
    -> Ix a
    $crange :: (Point, Point) -> [Point]
    range :: (Point, Point) -> [Point]
    $cindex :: (Point, Point) -> Point -> Int
    index :: (Point, Point) -> Point -> Int
    $cunsafeIndex :: (Point, Point) -> Point -> Int
    unsafeIndex :: (Point, Point) -> Point -> Int
    $cinRange :: (Point, Point) -> Point -> Bool
    inRange :: (Point, Point) -> Point -> Bool
    $crangeSize :: (Point, Point) -> Int
    rangeSize :: (Point, Point) -> Int
    $cunsafeRangeSize :: (Point, Point) -> Int
    unsafeRangeSize :: (Point, Point) -> Int
    Ix,
                  Integer -> Point
    Point -> Point
    Point -> Point -> Point
    (Point -> Point -> Point)
    -> (Point -> Point -> Point)
    -> (Point -> Point -> Point)
    -> (Point -> Point)
    -> (Point -> Point)
    -> (Point -> Point)
    -> (Integer -> Point)
    -> Num Point
    forall a.
    (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a)
    -> (a -> a)
    -> (a -> a)
    -> (Integer -> a)
    -> Num a
    $c+ :: Point -> Point -> Point
    + :: Point -> Point -> Point
    $c- :: Point -> Point -> Point
    - :: Point -> Point -> Point
    $c* :: Point -> Point -> Point
    * :: Point -> Point -> Point
    $cnegate :: Point -> Point
    negate :: Point -> Point
    $cabs :: Point -> Point
    abs :: Point -> Point
    $csignum :: Point -> Point
    signum :: Point -> Point
    $cfromInteger :: Integer -> Point
    fromInteger :: Integer -> Point
    Num, Num Point
    Ord Point
    (Num Point, Ord Point) => (Point -> Rational) -> Real Point
    Point -> Rational
    forall a. (Num a, Ord a) => (a -> Rational) -> Real a
    $ctoRational :: Point -> Rational
    toRational :: Point -> Rational
    Real, Enum Point
    Real Point
    (Real Point, Enum Point) =>
    (Point -> Point -> Point)
    -> (Point -> Point -> Point)
    -> (Point -> Point -> Point)
    -> (Point -> Point -> Point)
    -> (Point -> Point -> (Point, Point))
    -> (Point -> Point -> (Point, Point))
    -> (Point -> Integer)
    -> Integral Point
    Point -> Integer
    Point -> Point -> (Point, Point)
    Point -> Point -> Point
    forall a.
    (Real a, Enum a) =>
    (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a -> (a, a))
    -> (a -> a -> (a, a))
    -> (a -> Integer)
    -> Integral a
    $cquot :: Point -> Point -> Point
    quot :: Point -> Point -> Point
    $crem :: Point -> Point -> Point
    rem :: Point -> Point -> Point
    $cdiv :: Point -> Point -> Point
    div :: Point -> Point -> Point
    $cmod :: Point -> Point -> Point
    mod :: Point -> Point -> Point
    $cquotRem :: Point -> Point -> (Point, Point)
    quotRem :: Point -> Point -> (Point, Point)
    $cdivMod :: Point -> Point -> (Point, Point)
    divMod :: Point -> Point -> (Point, Point)
    $ctoInteger :: Point -> Integer
    toInteger :: Point -> Integer
    Integral)

    instance Show Point where
        show :: Point -> String
    show (Point Int
    p) = Int -> String
    forall a. Show a => a -> String
    show Int
    p

    -- | Size of a buffer region
    newtype Size = Size {Size -> Int
    fromSize :: Int}             -- size in bytes (#bytes, NOT codepoints)
        deriving (Int -> Size -> ShowS
    [Size] -> ShowS
    Size -> String
    (Int -> Size -> ShowS)
    -> (Size -> String) -> ([Size] -> ShowS) -> Show Size
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> Size -> ShowS
    showsPrec :: Int -> Size -> ShowS
    $cshow :: Size -> String
    show :: Size -> String
    $cshowList :: [Size] -> ShowS
    showList :: [Size] -> ShowS
    Show, Size -> Size -> Bool
    (Size -> Size -> Bool) -> (Size -> Size -> Bool) -> Eq Size
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: Size -> Size -> Bool
    == :: Size -> Size -> Bool
    $c/= :: Size -> Size -> Bool
    /= :: Size -> Size -> Bool
    Eq, Eq Size
    Eq Size =>
    (Size -> Size -> Ordering)
    -> (Size -> Size -> Bool)
    -> (Size -> Size -> Bool)
    -> (Size -> Size -> Bool)
    -> (Size -> Size -> Bool)
    -> (Size -> Size -> Size)
    -> (Size -> Size -> Size)
    -> Ord Size
    Size -> Size -> Bool
    Size -> Size -> Ordering
    Size -> Size -> Size
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: Size -> Size -> Ordering
    compare :: Size -> Size -> Ordering
    $c< :: Size -> Size -> Bool
    < :: Size -> Size -> Bool
    $c<= :: Size -> Size -> Bool
    <= :: Size -> Size -> Bool
    $c> :: Size -> Size -> Bool
    > :: Size -> Size -> Bool
    $c>= :: Size -> Size -> Bool
    >= :: Size -> Size -> Bool
    $cmax :: Size -> Size -> Size
    max :: Size -> Size -> Size
    $cmin :: Size -> Size -> Size
    min :: Size -> Size -> Size
    Ord, Integer -> Size
    Size -> Size
    Size -> Size -> Size
    (Size -> Size -> Size)
    -> (Size -> Size -> Size)
    -> (Size -> Size -> Size)
    -> (Size -> Size)
    -> (Size -> Size)
    -> (Size -> Size)
    -> (Integer -> Size)
    -> Num Size
    forall a.
    (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a)
    -> (a -> a)
    -> (a -> a)
    -> (Integer -> a)
    -> Num a
    $c+ :: Size -> Size -> Size
    + :: Size -> Size -> Size
    $c- :: Size -> Size -> Size
    - :: Size -> Size -> Size
    $c* :: Size -> Size -> Size
    * :: Size -> Size -> Size
    $cnegate :: Size -> Size
    negate :: Size -> Size
    $cabs :: Size -> Size
    abs :: Size -> Size
    $csignum :: Size -> Size
    signum :: Size -> Size
    $cfromInteger :: Integer -> Size
    fromInteger :: Integer -> Size
    Num, Int -> Size
    Size -> Int
    Size -> [Size]
    Size -> Size
    Size -> Size -> [Size]
    Size -> Size -> Size -> [Size]
    (Size -> Size)
    -> (Size -> Size)
    -> (Int -> Size)
    -> (Size -> Int)
    -> (Size -> [Size])
    -> (Size -> Size -> [Size])
    -> (Size -> Size -> [Size])
    -> (Size -> Size -> Size -> [Size])
    -> Enum Size
    forall a.
    (a -> a)
    -> (a -> a)
    -> (Int -> a)
    -> (a -> Int)
    -> (a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> a -> [a])
    -> Enum a
    $csucc :: Size -> Size
    succ :: Size -> Size
    $cpred :: Size -> Size
    pred :: Size -> Size
    $ctoEnum :: Int -> Size
    toEnum :: Int -> Size
    $cfromEnum :: Size -> Int
    fromEnum :: Size -> Int
    $cenumFrom :: Size -> [Size]
    enumFrom :: Size -> [Size]
    $cenumFromThen :: Size -> Size -> [Size]
    enumFromThen :: Size -> Size -> [Size]
    $cenumFromTo :: Size -> Size -> [Size]
    enumFromTo :: Size -> Size -> [Size]
    $cenumFromThenTo :: Size -> Size -> Size -> [Size]
    enumFromThenTo :: Size -> Size -> Size -> [Size]
    Enum, Num Size
    Ord Size
    (Num Size, Ord Size) => (Size -> Rational) -> Real Size
    Size -> Rational
    forall a. (Num a, Ord a) => (a -> Rational) -> Real a
    $ctoRational :: Size -> Rational
    toRational :: Size -> Rational
    Real, Enum Size
    Real Size
    (Real Size, Enum Size) =>
    (Size -> Size -> Size)
    -> (Size -> Size -> Size)
    -> (Size -> Size -> Size)
    -> (Size -> Size -> Size)
    -> (Size -> Size -> (Size, Size))
    -> (Size -> Size -> (Size, Size))
    -> (Size -> Integer)
    -> Integral Size
    Size -> Integer
    Size -> Size -> (Size, Size)
    Size -> Size -> Size
    forall a.
    (Real a, Enum a) =>
    (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> (a -> a -> (a, a))
    -> (a -> a -> (a, a))
    -> (a -> Integer)
    -> Integral a
    $cquot :: Size -> Size -> Size
    quot :: Size -> Size -> Size
    $crem :: Size -> Size -> Size
    rem :: Size -> Size -> Size
    $cdiv :: Size -> Size -> Size
    div :: Size -> Size -> Size
    $cmod :: Size -> Size -> Size
    mod :: Size -> Size -> Size
    $cquotRem :: Size -> Size -> (Size, Size)
    quotRem :: Size -> Size -> (Size, Size)
    $cdivMod :: Size -> Size -> (Size, Size)
    divMod :: Size -> Size -> (Size, Size)
    $ctoInteger :: Size -> Integer
    toInteger :: Size -> Integer
    Integral, Get Size
    [Size] -> Put
    Size -> Put
    (Size -> Put) -> Get Size -> ([Size] -> Put) -> Binary Size
    forall t. (t -> Put) -> Get t -> ([t] -> Put) -> Binary t
    $cput :: Size -> Put
    put :: Size -> Put
    $cget :: Get Size
    get :: Get Size
    $cputList :: [Size] -> Put
    putList :: [Size] -> Put
    Binary)

    instance SemiNum Point Size where
        Point Int
    p +~ :: Point -> Size -> Point
    +~ Size Int
    s = Int -> Point
    Point (Int
    p Int -> Int -> Int
    forall a. Num a => a -> a -> a
    + Int
    s)
        Point Int
    p -~ :: Point -> Size -> Point
    -~ Size Int
    s = Int -> Point
    Point (Int
    p Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    s)
        Point Int
    p ~- :: Point -> Point -> Size
    ~- Point Int
    q = Int -> Size
    Size (Int -> Int
    forall a. Num a => a -> a
    abs (Int
    p Int -> Int -> Int
    forall a. Num a => a -> a -> a
    - Int
    q))

    -- | Window references
    newtype WindowRef = WindowRef { WindowRef -> Int
    unWindowRef :: Int }
      deriving(WindowRef -> WindowRef -> Bool
    (WindowRef -> WindowRef -> Bool)
    -> (WindowRef -> WindowRef -> Bool) -> Eq WindowRef
    forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
    $c== :: WindowRef -> WindowRef -> Bool
    == :: WindowRef -> WindowRef -> Bool
    $c/= :: WindowRef -> WindowRef -> Bool
    /= :: WindowRef -> WindowRef -> Bool
    Eq, Eq WindowRef
    Eq WindowRef =>
    (WindowRef -> WindowRef -> Ordering)
    -> (WindowRef -> WindowRef -> Bool)
    -> (WindowRef -> WindowRef -> Bool)
    -> (WindowRef -> WindowRef -> Bool)
    -> (WindowRef -> WindowRef -> Bool)
    -> (WindowRef -> WindowRef -> WindowRef)
    -> (WindowRef -> WindowRef -> WindowRef)
    -> Ord WindowRef
    WindowRef -> WindowRef -> Bool
    WindowRef -> WindowRef -> Ordering
    WindowRef -> WindowRef -> WindowRef
    forall a.
    Eq a =>
    (a -> a -> Ordering)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> Bool)
    -> (a -> a -> a)
    -> (a -> a -> a)
    -> Ord a
    $ccompare :: WindowRef -> WindowRef -> Ordering
    compare :: WindowRef -> WindowRef -> Ordering
    $c< :: WindowRef -> WindowRef -> Bool
    < :: WindowRef -> WindowRef -> Bool
    $c<= :: WindowRef -> WindowRef -> Bool
    <= :: WindowRef -> WindowRef -> Bool
    $c> :: WindowRef -> WindowRef -> Bool
    > :: WindowRef -> WindowRef -> Bool
    $c>= :: WindowRef -> WindowRef -> Bool
    >= :: WindowRef -> WindowRef -> Bool
    $cmax :: WindowRef -> WindowRef -> WindowRef
    max :: WindowRef -> WindowRef -> WindowRef
    $cmin :: WindowRef -> WindowRef -> WindowRef
    min :: WindowRef -> WindowRef -> WindowRef
    Ord, Int -> WindowRef
    WindowRef -> Int
    WindowRef -> [WindowRef]
    WindowRef -> WindowRef
    WindowRef -> WindowRef -> [WindowRef]
    WindowRef -> WindowRef -> WindowRef -> [WindowRef]
    (WindowRef -> WindowRef)
    -> (WindowRef -> WindowRef)
    -> (Int -> WindowRef)
    -> (WindowRef -> Int)
    -> (WindowRef -> [WindowRef])
    -> (WindowRef -> WindowRef -> [WindowRef])
    -> (WindowRef -> WindowRef -> [WindowRef])
    -> (WindowRef -> WindowRef -> WindowRef -> [WindowRef])
    -> Enum WindowRef
    forall a.
    (a -> a)
    -> (a -> a)
    -> (Int -> a)
    -> (a -> Int)
    -> (a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> [a])
    -> (a -> a -> a -> [a])
    -> Enum a
    $csucc :: WindowRef -> WindowRef
    succ :: WindowRef -> WindowRef
    $cpred :: WindowRef -> WindowRef
    pred :: WindowRef -> WindowRef
    $ctoEnum :: Int -> WindowRef
    toEnum :: Int -> WindowRef
    $cfromEnum :: WindowRef -> Int
    fromEnum :: WindowRef -> Int
    $cenumFrom :: WindowRef -> [WindowRef]
    enumFrom :: WindowRef -> [WindowRef]
    $cenumFromThen :: WindowRef -> WindowRef -> [WindowRef]
    enumFromThen :: WindowRef -> WindowRef -> [WindowRef]
    $cenumFromTo :: WindowRef -> WindowRef -> [WindowRef]
    enumFromTo :: WindowRef -> WindowRef -> [WindowRef]
    $cenumFromThenTo :: WindowRef -> WindowRef -> WindowRef -> [WindowRef]
    enumFromThenTo :: WindowRef -> WindowRef -> WindowRef -> [WindowRef]
    Enum, Int -> WindowRef -> ShowS
    [WindowRef] -> ShowS
    WindowRef -> String
    (Int -> WindowRef -> ShowS)
    -> (WindowRef -> String)
    -> ([WindowRef] -> ShowS)
    -> Show WindowRef
    forall a.
    (Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
    $cshowsPrec :: Int -> WindowRef -> ShowS
    showsPrec :: Int -> WindowRef -> ShowS
    $cshow :: WindowRef -> String
    show :: WindowRef -> String
    $cshowList :: [WindowRef] -> ShowS
    showList :: [WindowRef] -> ShowS
    Show, Typeable, Get WindowRef
    [WindowRef] -> Put
    WindowRef -> Put
    (WindowRef -> Put)
    -> Get WindowRef -> ([WindowRef] -> Put) -> Binary WindowRef
    forall t. (t -> Put) -> Get t -> ([t] -> Put) -> Binary t
    $cput :: WindowRef -> Put
    put :: WindowRef -> Put
    $cget :: Get WindowRef
    get :: Get WindowRef
    $cputList :: [WindowRef] -> Put
    putList :: [WindowRef] -> Put
    Binary)

    instance Default WindowRef where def :: WindowRef
    def = Int -> WindowRef
    WindowRef (-Int
    1)