[<<][meta][>>][..]
Sat Feb 20 21:38:46 CET 2010

Type-level vector size specifications

-- I tried the following, but it's not what I wanted: it can only
-- construct size 2^N structures


import Control.Applicative

data Tensor a = a :* a  deriving (Show, Eq)
infixr 5 :*


instance Functor Tensor where
    fmap f (x :* y) = (f x) :* (f y)


instance Applicative Tensor where
    pure x = x :* x
    (fx :* fy) <*> ( x :* y) = (fx x) :* (fy y)

    

instance (Eq a, Num a) => Num (Tensor a) where
    (+) = liftA2 (+)
    (*) = liftA2 (*)
    abs = fmap abs
    signum = fmap signum
    fromInteger i = let x = fromInteger i in x :* x



-- For more info see [1] and [2].
-- [1] http://www.mail-archive.com/haskell@haskell.org/msg16605.html
-- [2] http://www.eecs.usma.edu/webs/people/okasaki/icfp99.ps



[Reply][About]
[<<][meta][>>][..]