sized-grid-0.1.1.5: Multidimensional grids with sized specified at compile time

Safe HaskellNone
LanguageHaskell2010

SizedGrid.Coord

Synopsis

Documentation

type family Length cs where ... Source #

Length of a type level list

Equations

Length '[] = 0 
Length (c ': cs) = (+) 1 (Length cs) 

newtype Coord cs Source #

A multideminsion coordinate

Constructors

Coord 

Fields

Instances
All Eq cs => Eq (Coord cs) Source # 
Instance details

Defined in SizedGrid.Coord

Methods

(==) :: Coord cs -> Coord cs -> Bool #

(/=) :: Coord cs -> Coord cs -> Bool #

(All Eq cs, All Ord cs) => Ord (Coord cs) Source # 
Instance details

Defined in SizedGrid.Coord

Methods

compare :: Coord cs -> Coord cs -> Ordering #

(<) :: Coord cs -> Coord cs -> Bool #

(<=) :: Coord cs -> Coord cs -> Bool #

(>) :: Coord cs -> Coord cs -> Bool #

(>=) :: Coord cs -> Coord cs -> Bool #

max :: Coord cs -> Coord cs -> Coord cs #

min :: Coord cs -> Coord cs -> Coord cs #

All Show cs => Show (Coord cs) Source # 
Instance details

Defined in SizedGrid.Coord

Methods

showsPrec :: Int -> Coord cs -> ShowS #

show :: Coord cs -> String #

showList :: [Coord cs] -> ShowS #

Generic (Coord cs) Source # 
Instance details

Defined in SizedGrid.Coord

Associated Types

type Rep (Coord cs) :: Type -> Type #

Methods

from :: Coord cs -> Rep (Coord cs) x #

to :: Rep (Coord cs) x -> Coord cs #

All Semigroup cs => Semigroup (Coord cs) Source # 
Instance details

Defined in SizedGrid.Coord

Methods

(<>) :: Coord cs -> Coord cs -> Coord cs #

sconcat :: NonEmpty (Coord cs) -> Coord cs #

stimes :: Integral b => b -> Coord cs -> Coord cs #

(All Semigroup cs, All Monoid cs) => Monoid (Coord cs) Source # 
Instance details

Defined in SizedGrid.Coord

Methods

mempty :: Coord cs #

mappend :: Coord cs -> Coord cs -> Coord cs #

mconcat :: [Coord cs] -> Coord cs #

All ToJSON cs => ToJSON (Coord cs) Source # 
Instance details

Defined in SizedGrid.Coord

All FromJSON cs => FromJSON (Coord cs) Source # 
Instance details

Defined in SizedGrid.Coord

All Random cs => Random (Coord cs) Source # 
Instance details

Defined in SizedGrid.Coord

Methods

randomR :: RandomGen g => (Coord cs, Coord cs) -> g -> (Coord cs, g) #

random :: RandomGen g => g -> (Coord cs, g) #

randomRs :: RandomGen g => (Coord cs, Coord cs) -> g -> [Coord cs] #

randoms :: RandomGen g => g -> [Coord cs] #

randomRIO :: (Coord cs, Coord cs) -> IO (Coord cs) #

randomIO :: IO (Coord cs) #

(All AffineSpace cs, AdditiveGroup (CoordDiff cs), IsProductType (CoordDiff cs) (MapDiff cs)) => AffineSpace (Coord cs) Source # 
Instance details

Defined in SizedGrid.Coord

Associated Types

type Diff (Coord cs) :: Type #

Methods

(.-.) :: Coord cs -> Coord cs -> Diff (Coord cs) #

(.+^) :: Coord cs -> Diff (Coord cs) -> Coord cs #

All AdditiveGroup cs => AdditiveGroup (Coord cs) Source # 
Instance details

Defined in SizedGrid.Coord

Methods

zeroV :: Coord cs #

(^+^) :: Coord cs -> Coord cs -> Coord cs #

negateV :: Coord cs -> Coord cs #

(^-^) :: Coord cs -> Coord cs -> Coord cs #

(AllSizedKnown cs, All IsCoord cs, All Monoid cs, All Semigroup cs, SListI cs) => ComonadStore (Coord cs) (FocusedGrid cs) Source # 
Instance details

Defined in SizedGrid.Grid.Focused

Methods

pos :: FocusedGrid cs a -> Coord cs #

peek :: Coord cs -> FocusedGrid cs a -> a #

peeks :: (Coord cs -> Coord cs) -> FocusedGrid cs a -> a #

seek :: Coord cs -> FocusedGrid cs a -> FocusedGrid cs a #

seeks :: (Coord cs -> Coord cs) -> FocusedGrid cs a -> FocusedGrid cs a #

experiment :: Functor f => (Coord cs -> f (Coord cs)) -> FocusedGrid cs a -> f a #

All IsCoord cs => FunctorWithIndex (Coord cs) (Grid cs) Source # 
Instance details

Defined in SizedGrid.Grid.Grid

Methods

imap :: (Coord cs -> a -> b) -> Grid cs a -> Grid cs b #

imapped :: IndexedSetter (Coord cs) (Grid cs a) (Grid cs b) a b #

All IsCoord cs => FoldableWithIndex (Coord cs) (Grid cs) Source # 
Instance details

Defined in SizedGrid.Grid.Grid

Methods

ifoldMap :: Monoid m => (Coord cs -> a -> m) -> Grid cs a -> m #

ifolded :: IndexedFold (Coord cs) (Grid cs a) a #

ifoldr :: (Coord cs -> a -> b -> b) -> b -> Grid cs a -> b #

ifoldl :: (Coord cs -> b -> a -> b) -> b -> Grid cs a -> b #

ifoldr' :: (Coord cs -> a -> b -> b) -> b -> Grid cs a -> b #

ifoldl' :: (Coord cs -> b -> a -> b) -> b -> Grid cs a -> b #

All IsCoord cs => TraversableWithIndex (Coord cs) (Grid cs) Source # 
Instance details

Defined in SizedGrid.Grid.Grid

Methods

itraverse :: Applicative f => (Coord cs -> a -> f b) -> Grid cs a -> f (Grid cs b) #

itraversed :: IndexedTraversal (Coord cs) (Grid cs a) (Grid cs b) a b #

Field1 (Coord (a ': cs)) (Coord (a' ': cs)) a a' Source # 
Instance details

Defined in SizedGrid.Coord

Methods

_1 :: Lens (Coord (a ': cs)) (Coord (a' ': cs)) a a' #

Field2 (Coord (a ': (b ': cs))) (Coord (a ': (b' ': cs))) b b' Source # 
Instance details

Defined in SizedGrid.Coord

Methods

_2 :: Lens (Coord (a ': (b ': cs))) (Coord (a ': (b' ': cs))) b b' #

Field3 (Coord (a ': (b ': (c ': cs)))) (Coord (a ': (b ': (c' ': cs)))) c c' Source # 
Instance details

Defined in SizedGrid.Coord

Methods

_3 :: Lens (Coord (a ': (b ': (c ': cs)))) (Coord (a ': (b ': (c' ': cs)))) c c' #

Field4 (Coord (a ': (b ': (c ': (d ': cs))))) (Coord (a ': (b ': (c ': (d' ': cs))))) d d' Source # 
Instance details

Defined in SizedGrid.Coord

Methods

_4 :: Lens (Coord (a ': (b ': (c ': (d ': cs))))) (Coord (a ': (b ': (c ': (d' ': cs))))) d d' #

Field5 (Coord (a ': (b ': (c ': (d ': (e ': cs)))))) (Coord (a ': (b ': (c ': (d ': (e' ': cs)))))) e e' Source # 
Instance details

Defined in SizedGrid.Coord

Methods

_5 :: Lens (Coord (a ': (b ': (c ': (d ': (e ': cs)))))) (Coord (a ': (b ': (c ': (d ': (e' ': cs)))))) e e' #

type Rep (Coord cs) Source # 
Instance details

Defined in SizedGrid.Coord

type Rep (Coord cs) = D1 (MetaData "Coord" "SizedGrid.Coord" "sized-grid-0.1.1.5-KU5jkLUCL2P2O7tFE4dPdR" True) (C1 (MetaCons "Coord" PrefixI True) (S1 (MetaSel (Just "unCoord") NoSourceUnpackedness NoSourceStrictness DecidedLazy) (Rec0 (NP I cs))))
type Diff (Coord cs) Source # 
Instance details

Defined in SizedGrid.Coord

type Diff (Coord cs) = CoordDiff cs

coordSplit :: Coord (c ': cs) -> (c, Coord cs) Source #

pattern (:|) :: c -> Coord cs -> Coord (c ': cs) infixr 5 Source #

pattern EmptyCoord :: Coord '[] Source #

coordHead :: Lens (Coord (a ': as)) (Coord (a' ': as)) a a' Source #

Get the first element of a coord. Thanks to type level information, we can write this as a total Lens

coordTail :: Lens (Coord (a ': as)) (Coord (a ': as')) (Coord as) (Coord as') Source #

A Lens into the the tail of Coord

singleCoord :: a -> Coord '[a] Source #

Turn a single element into a one dimensional Coord

appendCoord :: a -> Coord as -> Coord (a ': as) Source #

Add a new element to a Coord. This increases the dimensionality

type family CoordDiff (cs :: [k]) :: * Source #

The type of difference between two coords. A n-dimensional coord should have a Diff of an n-tuple of Integers. We use Identity and our 1-tuple. Unfortuantly, each instance is manual at the moment.

Instances
type CoordDiff ([] :: [k]) Source # 
Instance details

Defined in SizedGrid.Coord

type CoordDiff ([] :: [k]) = ()
type CoordDiff (a ': (b ': (c ': (d ': (e ': (f ': ([] :: [Type])))))) :: [Type]) Source # 
Instance details

Defined in SizedGrid.Coord

type CoordDiff (a ': (b ': (c ': (d ': (e ': (f ': ([] :: [Type])))))) :: [Type]) = (Diff a, Diff b, Diff c, Diff d, Diff e, Diff f)
type CoordDiff (a ': (b ': (c ': (d ': (e ': ([] :: [Type]))))) :: [Type]) Source # 
Instance details

Defined in SizedGrid.Coord

type CoordDiff (a ': (b ': (c ': (d ': (e ': ([] :: [Type]))))) :: [Type]) = (Diff a, Diff b, Diff c, Diff d, Diff e)
type CoordDiff (a ': (b ': (c ': (d ': ([] :: [Type])))) :: [Type]) Source # 
Instance details

Defined in SizedGrid.Coord

type CoordDiff (a ': (b ': (c ': (d ': ([] :: [Type])))) :: [Type]) = (Diff a, Diff b, Diff c, Diff d)
type CoordDiff (a ': (b ': (c ': ([] :: [Type]))) :: [Type]) Source # 
Instance details

Defined in SizedGrid.Coord

type CoordDiff (a ': (b ': (c ': ([] :: [Type]))) :: [Type]) = (Diff a, Diff b, Diff c)
type CoordDiff (a ': (b ': ([] :: [Type])) :: [Type]) Source # 
Instance details

Defined in SizedGrid.Coord

type CoordDiff (a ': (b ': ([] :: [Type])) :: [Type]) = (Diff a, Diff b)
type CoordDiff (a ': ([] :: [Type]) :: [Type]) Source # 
Instance details

Defined in SizedGrid.Coord

type CoordDiff (a ': ([] :: [Type]) :: [Type]) = Identity (Diff a)

type family MapDiff xs where ... Source #

Apply Diff to each element of a type level list. This is required as type families can't be partially applied.

Equations

MapDiff '[] = '[] 
MapDiff (x ': xs) = Diff x ': MapDiff xs 

allCoord :: forall cs. All IsCoord cs => [Coord cs] Source #

Generate all possible coords in order

type family MaxCoordSize (cs :: [k]) :: Nat where ... Source #

The number of elements a coord can have. This is equal to the product of the CoordSized of each element

Equations

MaxCoordSize '[] = 1 
MaxCoordSize (c ': cs) = CoordSized c * MaxCoordSize cs 

coordPosition :: All IsCoord cs => Coord cs -> Int Source #

Convert a Coord to its position in a vector

type family AllDiffSame a xs :: Constraint where ... Source #

All Diffs of the members of the list must be equal

Equations

AllDiffSame _ '[] = () 
AllDiffSame a (x ': xs) = (Diff x ~ a, AllDiffSame a xs) 

moorePoints :: forall a cs. (Enum a, Num a, AllDiffSame a cs, All AffineSpace cs) => a -> Coord cs -> [Coord cs] Source #

Calculate the Moore neighbourhood around a point. Includes the center

vonNeumanPoints :: forall a cs. (Enum a, Num a, Ord a, All Integral (MapDiff cs), AllDiffSame a cs, All AffineSpace cs, Ord (CoordDiff cs), IsProductType (CoordDiff cs) (MapDiff cs), AdditiveGroup (CoordDiff cs)) => a -> Coord cs -> [Coord cs] Source #

Calculate the von Neuman neighbourhood around a point. Includes the center

tranposeCoord :: Coord '[a, b] -> Coord '[b, a] Source #

Swap x and y for a coord in 2D space

zeroCoord :: All IsCoord cs => Coord cs Source #

The zero position for a coord

class AllSizedKnown (cs :: [*]) where Source #

Instances
AllSizedKnown ([] :: [Type]) Source # 
Instance details

Defined in SizedGrid.Coord

(KnownNat (CoordSized a), AllSizedKnown as) => AllSizedKnown (a ': as) Source # 
Instance details

Defined in SizedGrid.Coord

Methods

sizeProof :: Dict (KnownNat (MaxCoordSize (a ': as))) Source #

class WeakenCoord as bs where Source #

Methods

weakenCoord :: Coord as -> Maybe (Coord bs) Source #

Instances
WeakenCoord ([] :: [Type]) ([] :: [Type]) Source # 
Instance details

Defined in SizedGrid.Coord

Methods

weakenCoord :: Coord [] -> Maybe (Coord []) Source #

(b ~ CoordFromNat a n, WeakenCoord as bs, IsCoord a, IsCoord (CoordFromNat a n)) => WeakenCoord (a ': as) (b ': bs) Source # 
Instance details

Defined in SizedGrid.Coord

Methods

weakenCoord :: Coord (a ': as) -> Maybe (Coord (b ': bs)) Source #

class StrengthenCoord as bs where Source #

Methods

strengthenCoord :: Coord as -> Coord bs Source #

Instances
StrengthenCoord ([] :: [Type]) ([] :: [Type]) Source # 
Instance details

Defined in SizedGrid.Coord

Methods

strengthenCoord :: Coord [] -> Coord [] Source #

(StrengthenCoord as bs, IsCoord (CoordFromNat a n), IsCoord a, b ~ CoordFromNat a n, CoordSized a <= CoordSized (CoordFromNat a n)) => StrengthenCoord (a ': as) (b ': bs) Source # 
Instance details

Defined in SizedGrid.Coord

Methods

strengthenCoord :: Coord (a ': as) -> Coord (b ': bs) Source #