Naperian-0.1.1.0: Naperian Functors for APL-like programming

Naperian

Synopsis

# Documentation

data Finite :: Nat -> Type where Source #

The finite set of type-bounded Naturals. A value of type Fin n has exactly n inhabitants, the natural numbers from [0..n-1].

Constructors

 Fin :: Int -> Finite n
Instances
 Eq (Finite a) Source # Instance detailsDefined in Naperian Methods(==) :: Finite a -> Finite a -> Bool #(/=) :: Finite a -> Finite a -> Bool # Show (Finite a) Source # Instance detailsDefined in Naperian MethodsshowsPrec :: Int -> Finite a -> ShowS #show :: Finite a -> String #showList :: [Finite a] -> ShowS #

finite :: forall n. KnownNat n => Int -> Maybe (Finite n) Source #

Create a type-bounded finite number Fin n from a runtime integer, bounded to a statically known limit. If the input value x > n, then Nothing is returned. Otherwise, returns Just (x :: Fin n).

azipWith :: Applicative f => (a -> b -> c) -> f a -> f b -> f c Source #

"Applicative zipping".

showVector :: [String] -> String Source #

Format a vector to make it look nice.

data Pair a Source #

The cartesian product of a, equivalent to (a, a).

Constructors

 Pair a a
Instances
 Source # Instance detailsDefined in Naperian Methodsfmap :: (a -> b) -> Pair a -> Pair b #(<$) :: a -> Pair b -> Pair a # Source # Instance detailsDefined in Naperian Methodspure :: a -> Pair a #(<*>) :: Pair (a -> b) -> Pair a -> Pair b #liftA2 :: (a -> b -> c) -> Pair a -> Pair b -> Pair c #(*>) :: Pair a -> Pair b -> Pair b #(<*) :: Pair a -> Pair b -> Pair a # Source # Instance detailsDefined in Naperian Methodsfold :: Monoid m => Pair m -> m #foldMap :: Monoid m => (a -> m) -> Pair a -> m #foldr :: (a -> b -> b) -> b -> Pair a -> b #foldr' :: (a -> b -> b) -> b -> Pair a -> b #foldl :: (b -> a -> b) -> b -> Pair a -> b #foldl' :: (b -> a -> b) -> b -> Pair a -> b #foldr1 :: (a -> a -> a) -> Pair a -> a #foldl1 :: (a -> a -> a) -> Pair a -> a #toList :: Pair a -> [a] #null :: Pair a -> Bool #length :: Pair a -> Int #elem :: Eq a => a -> Pair a -> Bool #maximum :: Ord a => Pair a -> a #minimum :: Ord a => Pair a -> a #sum :: Num a => Pair a -> a #product :: Num a => Pair a -> a # Source # Instance detailsDefined in Naperian Methodstraverse :: Applicative f => (a -> f b) -> Pair a -> f (Pair b) #sequenceA :: Applicative f => Pair (f a) -> f (Pair a) #mapM :: Monad m => (a -> m b) -> Pair a -> m (Pair b) #sequence :: Monad m => Pair (m a) -> m (Pair a) # Source # Instance detailsDefined in Naperian Methodssize :: Pair a -> Int Source # Source # Instance detailsDefined in Naperian Associated Typestype Log Pair :: Type Source # Methodslookup :: Pair a -> Log Pair -> a Source #tabulate :: (Log Pair -> a) -> Pair a Source # Eq a => Eq (Pair a) Source # Instance detailsDefined in Naperian Methods(==) :: Pair a -> Pair a -> Bool #(/=) :: Pair a -> Pair a -> Bool # Ord a => Ord (Pair a) Source # Instance detailsDefined in Naperian Methodscompare :: Pair a -> Pair a -> Ordering #(<) :: Pair a -> Pair a -> Bool #(<=) :: Pair a -> Pair a -> Bool #(>) :: Pair a -> Pair a -> Bool #(>=) :: Pair a -> Pair a -> Bool #max :: Pair a -> Pair a -> Pair a #min :: Pair a -> Pair a -> Pair a # Show a => Show (Pair a) Source # Instance detailsDefined in Naperian MethodsshowsPrec :: Int -> Pair a -> ShowS #show :: Pair a -> String #showList :: [Pair a] -> ShowS # type Log Pair Source # Instance detailsDefined in Naperian type Log Pair = Bool newtype Vector (n :: Nat) a Source # Constructors  Vector (Vector a) Instances  Source # Instance detailsDefined in Naperian Methodsfmap :: (a -> b) -> Vector n a -> Vector n b #(<$) :: a -> Vector n b -> Vector n a # KnownNat n => Applicative (Vector n) Source # Instance detailsDefined in Naperian Methodspure :: a -> Vector n a #(<*>) :: Vector n (a -> b) -> Vector n a -> Vector n b #liftA2 :: (a -> b -> c) -> Vector n a -> Vector n b -> Vector n c #(*>) :: Vector n a -> Vector n b -> Vector n b #(<*) :: Vector n a -> Vector n b -> Vector n a # Source # Instance detailsDefined in Naperian Methodsfold :: Monoid m => Vector n m -> m #foldMap :: Monoid m => (a -> m) -> Vector n a -> m #foldr :: (a -> b -> b) -> b -> Vector n a -> b #foldr' :: (a -> b -> b) -> b -> Vector n a -> b #foldl :: (b -> a -> b) -> b -> Vector n a -> b #foldl' :: (b -> a -> b) -> b -> Vector n a -> b #foldr1 :: (a -> a -> a) -> Vector n a -> a #foldl1 :: (a -> a -> a) -> Vector n a -> a #toList :: Vector n a -> [a] #null :: Vector n a -> Bool #length :: Vector n a -> Int #elem :: Eq a => a -> Vector n a -> Bool #maximum :: Ord a => Vector n a -> a #minimum :: Ord a => Vector n a -> a #sum :: Num a => Vector n a -> a #product :: Num a => Vector n a -> a # Source # Instance detailsDefined in Naperian Methodstraverse :: Applicative f => (a -> f b) -> Vector n a -> f (Vector n b) #sequenceA :: Applicative f => Vector n (f a) -> f (Vector n a) #mapM :: Monad m => (a -> m b) -> Vector n a -> m (Vector n b) #sequence :: Monad m => Vector n (m a) -> m (Vector n a) # KnownNat n => Dimension (Vector n) Source # Instance detailsDefined in Naperian Methodssize :: Vector n a -> Int Source # KnownNat n => Naperian (Vector n) Source # Instance detailsDefined in Naperian Associated Typestype Log (Vector n) :: Type Source # Methodslookup :: Vector n a -> Log (Vector n) -> a Source #tabulate :: (Log (Vector n) -> a) -> Vector n a Source #positions :: Vector n (Log (Vector n)) Source # (KnownNat n, Traversable (Vector n)) => IsList (Vector n a) Source # Instance detailsDefined in Naperian Associated Typestype Item (Vector n a) :: Type # MethodsfromList :: [Item (Vector n a)] -> Vector n a #fromListN :: Int -> [Item (Vector n a)] -> Vector n a #toList :: Vector n a -> [Item (Vector n a)] # Eq a => Eq (Vector n a) Source # Instance detailsDefined in Naperian Methods(==) :: Vector n a -> Vector n a -> Bool #(/=) :: Vector n a -> Vector n a -> Bool # Ord a => Ord (Vector n a) Source # Instance detailsDefined in Naperian Methodscompare :: Vector n a -> Vector n a -> Ordering #(<) :: Vector n a -> Vector n a -> Bool #(<=) :: Vector n a -> Vector n a -> Bool #(>) :: Vector n a -> Vector n a -> Bool #(>=) :: Vector n a -> Vector n a -> Bool #max :: Vector n a -> Vector n a -> Vector n a #min :: Vector n a -> Vector n a -> Vector n a # Show a => Show (Vector n a) Source # Instance detailsDefined in Naperian MethodsshowsPrec :: Int -> Vector n a -> ShowS #show :: Vector n a -> String #showList :: [Vector n a] -> ShowS # type Log (Vector n) Source # Instance detailsDefined in Naperian type Log (Vector n) = Finite n type Item (Vector n a) Source # Instance detailsDefined in Naperian type Item (Vector n a) = a

tail :: Vector (n + 1) a -> Vector n a Source #

fromList :: forall n a. KnownNat n => [a] -> Maybe (Vector n a) Source #

zipWith :: (a -> b -> c) -> Vector n a -> Vector n b -> Vector n c Source #

length :: forall n a. KnownNat n => Vector n a -> Int Source #

replicate :: forall n a. KnownNat n => a -> Vector n a Source #

index :: Vector n a -> Finite n -> a Source #

viota :: forall n. KnownNat n => Vector n (Finite n) Source #

class Functor f => Naperian f where Source #

Naperian functors.

Minimal complete definition

Associated Types

type Log f Source #

The "logarithm" of f. This type represents the input you use to look up values inside f a. For example, if you have a list [a], and you want to look up a value, then you use an Int to index into the list. In this case, Log [a] = Int. If you have a type-bounded Vector Vector (n :: Nat) a, then Log (Vector n) is the range of integers [0..n-1] (represented here as Finite n.)

Methods

lookup :: f a -> Log f -> a Source #

Look up an element a inside f a. If you read this function type in english, it says "if you give me an f a, then I will give you a function, so you can look up the elements of f a and get back an a"

tabulate :: (Log f -> a) -> f a Source #

Tabulate a Naperian. This creates f a values by mapping the logarithm of f onto every "position" inside f a

positions :: f (Log f) Source #

Find every position in the "space" of the Naperian f.

Instances
 Source # Instance detailsDefined in Naperian Associated Typestype Log Pair :: Type Source # Methodslookup :: Pair a -> Log Pair -> a Source #tabulate :: (Log Pair -> a) -> Pair a Source # KnownNat n => Naperian (Vector n) Source # Instance detailsDefined in Naperian Associated Typestype Log (Vector n) :: Type Source # Methodslookup :: Vector n a -> Log (Vector n) -> a Source #tabulate :: (Log (Vector n) -> a) -> Vector n a Source #positions :: Vector n (Log (Vector n)) Source #

transpose :: (Naperian f, Naperian g) => f (g a) -> g (f a) Source #

The transposition of two Naperian functors f and g.

class (Applicative f, Naperian f, Traversable f) => Dimension f where Source #

Minimal complete definition

Nothing

Methods

size :: f a -> Int Source #

Instances
 Source # Instance detailsDefined in Naperian Methodssize :: Pair a -> Int Source # KnownNat n => Dimension (Vector n) Source # Instance detailsDefined in Naperian Methodssize :: Vector n a -> Int Source #

inner :: (Num a, Dimension f) => f a -> f a -> a Source #

matrix :: (Num a, Dimension f, Dimension g, Dimension h) => f (g a) -> g (h a) -> f (h a) Source #

data Hyper :: [Type -> Type] -> Type -> Type where Source #

Arbitrary-rank Hypercuboids, parameterized over their dimension.

Constructors

 Scalar :: a -> Hyper '[] a Prism :: (Dimension f, Shapely fs) => Hyper fs (f a) -> Hyper (f ': fs) a
Instances
 Functor (Hyper fs) Source # Instance detailsDefined in Naperian Methodsfmap :: (a -> b) -> Hyper fs a -> Hyper fs b #(<) :: a -> Hyper fs b -> Hyper fs a # Shapely fs => Applicative (Hyper fs) Source # Instance detailsDefined in Naperian Methodspure :: a -> Hyper fs a #(<*>) :: Hyper fs (a -> b) -> Hyper fs a -> Hyper fs b #liftA2 :: (a -> b -> c) -> Hyper fs a -> Hyper fs b -> Hyper fs c #(*>) :: Hyper fs a -> Hyper fs b -> Hyper fs b #(<*) :: Hyper fs a -> Hyper fs b -> Hyper fs a # Show a => Show (Hyper fs a) Source # Instance detailsDefined in Naperian MethodsshowsPrec :: Int -> Hyper fs a -> ShowS #show :: Hyper fs a -> String #showList :: [Hyper fs a] -> ShowS # point :: Hyper '[] a -> a Source # crystal :: Hyper (f ': fs) a -> Hyper fs (f a) Source # class Shapely fs where Source # Methods hreplicate :: a -> Hyper fs a Source # hsize :: Hyper fs a -> Int Source # Instances  Shapely ([] :: [Type -> Type]) Source # Instance detailsDefined in Naperian Methodshreplicate :: a -> Hyper [] a Source #hsize :: Hyper [] a -> Int Source # (Dimension f, Shapely fs) => Shapely (f ': fs) Source # Instance detailsDefined in Naperian Methodshreplicate :: a -> Hyper (f ': fs) a Source #hsize :: Hyper (f ': fs) a -> Int Source # hlookup :: Hyper (f ': fs) a -> Log f -> Hyper fs a Source # hzipWith :: (a -> b -> c) -> Hyper fs a -> Hyper fs b -> Hyper fs c Source # first :: Shapely fs => Hyper fs a -> a Source # transposeH :: Hyper (f ': (g ': fs)) a -> Hyper (g ': (f ': fs)) a Source # Generalized transposition over arbitrary-rank hypercuboids. transposeH' :: Hyper (f ': (g ': (h ': fs))) a -> Hyper (f ': (h ': (g ': fs))) a Source # foldrH :: (a -> a -> a) -> a -> Hyper (f ': fs) a -> Hyper fs a Source # Fold over a single dimension of a Hypercuboid. unary :: Shapely fs => (a -> b) -> Hyper fs a -> Hyper fs b Source # Lift an unary function from values to hypercuboids of values. binary :: (Compatible fs gs, Max fs gs ~ hs, Alignable fs hs, Alignable gs hs) => (a -> b -> c) -> Hyper fs a -> Hyper gs b -> Hyper hs c Source # Lift a binary function from values to two sets of hypercuboids, which can be aligned properly. up :: (Shapely fs, Dimension f) => Hyper fs a -> Hyper (f ': fs) a Source # innerH :: (Max fs gs ~ (f ': hs), Alignable fs (f ': hs), Alignable gs (f ': hs), Compatible fs gs, Num a) => Hyper fs a -> Hyper gs a -> Hyper hs a Source # Generalized, rank-polymorphic inner product. matrixH :: (Num a, Dimension f, Dimension g, Dimension h) => Hyper '[g, f] a -> Hyper '[h, g] a -> Hyper '[h, f] a Source # Generalized, rank-polymorphic matrix product. class (Shapely fs, Shapely gs) => Alignable fs gs where Source # Methods align :: Hyper fs a -> Hyper gs a Source # Instances  Alignable ([] :: [Type -> Type]) ([] :: [Type -> Type]) Source # Instance detailsDefined in Naperian Methodsalign :: Hyper [] a -> Hyper [] a Source # (Dimension f, Shapely fs) => Alignable ([] :: [Type -> Type]) (f ': fs) Source # Instance detailsDefined in Naperian Methodsalign :: Hyper [] a -> Hyper (f ': fs) a Source # (Dimension f, Alignable fs gs) => Alignable (f ': fs) (f ': gs) Source # Instance detailsDefined in Naperian Methodsalign :: Hyper (f ': fs) a -> Hyper (f ': gs) a Source # type family Max (fs :: [Type -> Type]) (gs :: [Type -> Type]) :: [Type -> Type] where ... Source # Equations  Max '[] '[] = '[] Max '[] (f ': gs) = f ': gs Max (f ': fs) '[] = f ': fs Max (f ': fs) (f ': gs) = f ': Max fs gs type family Compatible (fs :: [Type -> Type]) (gs :: [Type -> Type]) :: Constraint where ... Source # Equations  Compatible '[] '[] = () Compatible '[] (f ': gs) = () Compatible (f ': fs) '[] = () Compatible (f ': fs) (f ': gs) = Compatible fs gs Compatible a b = TypeError ((Text "Mismatched dimensions!" :: ((Text "The dimension " :<>: ShowType a) :<>: Text " can't be aligned with")) :: (Text "the dimension " :<>: ShowType b)) elements :: Shapely fs => Hyper fs a -> [a] Source # data Flat fs a where Source # Constructors  Flat :: Shapely fs => Vector a -> Flat fs a Instances  Functor (Flat fs) Source # Instance detailsDefined in Naperian Methodsfmap :: (a -> b) -> Flat fs a -> Flat fs b #(<) :: a -> Flat fs b -> Flat fs a # Show a => Show (Flat fs a) Source # Instance detailsDefined in Naperian MethodsshowsPrec :: Int -> Flat fs a -> ShowS #show :: Flat fs a -> String #showList :: [Flat fs a] -> ShowS #

flatten :: Shapely fs => Hyper fs a -> Flat fs a Source #

data Sparse fs a where Source #

Constructors

 Sparse :: Shapely fs => a -> IntMap a -> Sparse fs a

unsparse :: forall fs a. Shapely fs => Sparse fs a -> Flat fs a Source #

type Matrix n m v = Vector n (Vector m v) Source #