numhask-0.1.2: A numeric prelude

Safe HaskellNone
LanguageHaskell2010

NumHask.Shape

Contents

Description

numbers with a shape

Synopsis

Documentation

class HasShape f where Source #

Not everything that has a shape is representable.

todo: Structure is a useful alternative concept/naming convention

Minimal complete definition

shape

Associated Types

type Shape f Source #

Methods

shape :: f a -> Shape f Source #

Instances

HasShape SomeVector Source # 

Associated Types

type Shape (SomeVector :: * -> *) :: * Source #

HasShape SomeMatrix Source # 

Associated Types

type Shape (SomeMatrix :: * -> *) :: * Source #

KnownNat n => HasShape (Vector n) Source # 

Associated Types

type Shape (Vector n :: * -> *) :: * Source #

Methods

shape :: Vector n a -> Shape (Vector n) Source #

(KnownNat m, KnownNat n) => HasShape (Matrix Nat Nat m n) Source # 

Associated Types

type Shape (Matrix Nat Nat m n :: * -> *) :: * Source #

Methods

shape :: Matrix Nat Nat m n a -> Shape (Matrix Nat Nat m n) Source #

Representable

Representable has most of what's needed to define numbers that have elements (aka scalars) and a fixed shape.

class Distributive f => Representable f where #

A Functor f is Representable if tabulate and index witness an isomorphism to (->) x.

Every Distributive Functor is actually Representable.

Every Representable Functor from Hask to Hask is a right adjoint.

tabulate . index  ≡ id
index . tabulate  ≡ id
tabulate . returnreturn

Minimal complete definition

tabulate, index

Associated Types

type Rep (f :: * -> *) :: * #

Methods

tabulate :: (Rep f -> a) -> f a #

fmap f . tabulatetabulate . fmap f

index :: f a -> Rep f -> a #

Instances

Representable Identity 

Associated Types

type Rep (Identity :: * -> *) :: * #

Methods

tabulate :: (Rep Identity -> a) -> Identity a #

index :: Identity a -> Rep Identity -> a #

Representable Complex 

Associated Types

type Rep (Complex :: * -> *) :: * #

Methods

tabulate :: (Rep Complex -> a) -> Complex a #

index :: Complex a -> Rep Complex -> a #

Representable Dual 

Associated Types

type Rep (Dual :: * -> *) :: * #

Methods

tabulate :: (Rep Dual -> a) -> Dual a #

index :: Dual a -> Rep Dual -> a #

Representable Sum 

Associated Types

type Rep (Sum :: * -> *) :: * #

Methods

tabulate :: (Rep Sum -> a) -> Sum a #

index :: Sum a -> Rep Sum -> a #

Representable Product 

Associated Types

type Rep (Product :: * -> *) :: * #

Methods

tabulate :: (Rep Product -> a) -> Product a #

index :: Product a -> Rep Product -> a #

Representable ((->) e) 

Associated Types

type Rep ((->) e :: * -> *) :: * #

Methods

tabulate :: (Rep ((->) e) -> a) -> e -> a #

index :: (e -> a) -> Rep ((->) e) -> a #

Representable f => Representable (Co f) 

Associated Types

type Rep (Co f :: * -> *) :: * #

Methods

tabulate :: (Rep (Co f) -> a) -> Co f a #

index :: Co f a -> Rep (Co f) -> a #

Representable (Proxy *) 

Associated Types

type Rep (Proxy * :: * -> *) :: * #

Methods

tabulate :: (Rep (Proxy *) -> a) -> Proxy * a #

index :: Proxy * a -> Rep (Proxy *) -> a #

Representable f => Representable (Cofree f) 

Associated Types

type Rep (Cofree f :: * -> *) :: * #

Methods

tabulate :: (Rep (Cofree f) -> a) -> Cofree f a #

index :: Cofree f a -> Rep (Cofree f) -> a #

KnownNat n => Representable (Vector n) # 

Associated Types

type Rep (Vector n :: * -> *) :: * #

Methods

tabulate :: (Rep (Vector n) -> a) -> Vector n a #

index :: Vector n a -> Rep (Vector n) -> a #

Representable w => Representable (TracedT s w) 

Associated Types

type Rep (TracedT s w :: * -> *) :: * #

Methods

tabulate :: (Rep (TracedT s w) -> a) -> TracedT s w a #

index :: TracedT s w a -> Rep (TracedT s w) -> a #

Representable m => Representable (IdentityT * m) 

Associated Types

type Rep (IdentityT * m :: * -> *) :: * #

Methods

tabulate :: (Rep (IdentityT * m) -> a) -> IdentityT * m a #

index :: IdentityT * m a -> Rep (IdentityT * m) -> a #

Representable (Tagged * t) 

Associated Types

type Rep (Tagged * t :: * -> *) :: * #

Methods

tabulate :: (Rep (Tagged * t) -> a) -> Tagged * t a #

index :: Tagged * t a -> Rep (Tagged * t) -> a #

(Representable f, Representable g) => Representable (Product * f g) 

Associated Types

type Rep (Product * f g :: * -> *) :: * #

Methods

tabulate :: (Rep (Product * f g) -> a) -> Product * f g a #

index :: Product * f g a -> Rep (Product * f g) -> a #

Representable m => Representable (ReaderT * e m) 

Associated Types

type Rep (ReaderT * e m :: * -> *) :: * #

Methods

tabulate :: (Rep (ReaderT * e m) -> a) -> ReaderT * e m a #

index :: ReaderT * e m a -> Rep (ReaderT * e m) -> a #

(Representable f, Representable g) => Representable (Compose * * f g) 

Associated Types

type Rep (Compose * * f g :: * -> *) :: * #

Methods

tabulate :: (Rep (Compose * * f g) -> a) -> Compose * * f g a #

index :: Compose * * f g a -> Rep (Compose * * f g) -> a #

(KnownNat m, KnownNat n) => Representable (Matrix Nat Nat m n) # 

Associated Types

type Rep (Matrix Nat Nat m n :: * -> *) :: * #

Methods

tabulate :: (Rep (Matrix Nat Nat m n) -> a) -> Matrix Nat Nat m n a #

index :: Matrix Nat Nat m n a -> Rep (Matrix Nat Nat m n) -> a #

class Singleton f where Source #

This class could also be called replicate. Looking forward, however, it may be useful to consider a Representable such as

VectorThing a = Vector a | Single a | Zero

and then

singleton a = Single a
singleton zero = Zero

short-circuiting an expensive computation. As the class action then doesn't actually involve replication, it would be mis-named.

Minimal complete definition

singleton

Methods

singleton :: a -> f a Source #

Instances

Representable f => Singleton f Source # 

Methods

singleton :: a -> f a Source #