{- |
  1-dimensional vectors with vector arithmetic.

  This isn't especially useful. Usually if you want to calculate with scalars, you can just use the 'Scalar' type directly. However, this module provides a 'Vector1' newtype over 'Scalar' that allows a scalar to be treated as a sort of vector, which is very occasionally useful.
-}

{-# LANGUAGE GeneralizedNewtypeDeriving #-}

module Data.Vector.V1 where

import Data.Vector.Class

{- |
  The type of 1D vectors.

  Owing to its particularly simple structure, this type has more class instances than \'propper\' vectors have. Still, for the most part you'll probably want to just use 'Scalar' itself directly.
-}
newtype Vector1 = Vector1 {Vector1 -> Scalar
v1x :: Scalar} deriving (Vector1 -> Vector1 -> Bool
(Vector1 -> Vector1 -> Bool)
-> (Vector1 -> Vector1 -> Bool) -> Eq Vector1
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
$c== :: Vector1 -> Vector1 -> Bool
== :: Vector1 -> Vector1 -> Bool
$c/= :: Vector1 -> Vector1 -> Bool
/= :: Vector1 -> Vector1 -> Bool
Eq, Eq Vector1
Eq Vector1 =>
(Vector1 -> Vector1 -> Ordering)
-> (Vector1 -> Vector1 -> Bool)
-> (Vector1 -> Vector1 -> Bool)
-> (Vector1 -> Vector1 -> Bool)
-> (Vector1 -> Vector1 -> Bool)
-> (Vector1 -> Vector1 -> Vector1)
-> (Vector1 -> Vector1 -> Vector1)
-> Ord Vector1
Vector1 -> Vector1 -> Bool
Vector1 -> Vector1 -> Ordering
Vector1 -> Vector1 -> Vector1
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 :: Vector1 -> Vector1 -> Ordering
compare :: Vector1 -> Vector1 -> Ordering
$c< :: Vector1 -> Vector1 -> Bool
< :: Vector1 -> Vector1 -> Bool
$c<= :: Vector1 -> Vector1 -> Bool
<= :: Vector1 -> Vector1 -> Bool
$c> :: Vector1 -> Vector1 -> Bool
> :: Vector1 -> Vector1 -> Bool
$c>= :: Vector1 -> Vector1 -> Bool
>= :: Vector1 -> Vector1 -> Bool
$cmax :: Vector1 -> Vector1 -> Vector1
max :: Vector1 -> Vector1 -> Vector1
$cmin :: Vector1 -> Vector1 -> Vector1
min :: Vector1 -> Vector1 -> Vector1
Ord, Int -> Vector1
Vector1 -> Int
Vector1 -> [Vector1]
Vector1 -> Vector1
Vector1 -> Vector1 -> [Vector1]
Vector1 -> Vector1 -> Vector1 -> [Vector1]
(Vector1 -> Vector1)
-> (Vector1 -> Vector1)
-> (Int -> Vector1)
-> (Vector1 -> Int)
-> (Vector1 -> [Vector1])
-> (Vector1 -> Vector1 -> [Vector1])
-> (Vector1 -> Vector1 -> [Vector1])
-> (Vector1 -> Vector1 -> Vector1 -> [Vector1])
-> Enum Vector1
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 :: Vector1 -> Vector1
succ :: Vector1 -> Vector1
$cpred :: Vector1 -> Vector1
pred :: Vector1 -> Vector1
$ctoEnum :: Int -> Vector1
toEnum :: Int -> Vector1
$cfromEnum :: Vector1 -> Int
fromEnum :: Vector1 -> Int
$cenumFrom :: Vector1 -> [Vector1]
enumFrom :: Vector1 -> [Vector1]
$cenumFromThen :: Vector1 -> Vector1 -> [Vector1]
enumFromThen :: Vector1 -> Vector1 -> [Vector1]
$cenumFromTo :: Vector1 -> Vector1 -> [Vector1]
enumFromTo :: Vector1 -> Vector1 -> [Vector1]
$cenumFromThenTo :: Vector1 -> Vector1 -> Vector1 -> [Vector1]
enumFromThenTo :: Vector1 -> Vector1 -> Vector1 -> [Vector1]
Enum, Int -> Vector1 -> ShowS
[Vector1] -> ShowS
Vector1 -> String
(Int -> Vector1 -> ShowS)
-> (Vector1 -> String) -> ([Vector1] -> ShowS) -> Show Vector1
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
$cshowsPrec :: Int -> Vector1 -> ShowS
showsPrec :: Int -> Vector1 -> ShowS
$cshow :: Vector1 -> String
show :: Vector1 -> String
$cshowList :: [Vector1] -> ShowS
showList :: [Vector1] -> ShowS
Show, Integer -> Vector1
Vector1 -> Vector1
Vector1 -> Vector1 -> Vector1
(Vector1 -> Vector1 -> Vector1)
-> (Vector1 -> Vector1 -> Vector1)
-> (Vector1 -> Vector1 -> Vector1)
-> (Vector1 -> Vector1)
-> (Vector1 -> Vector1)
-> (Vector1 -> Vector1)
-> (Integer -> Vector1)
-> Num Vector1
forall a.
(a -> a -> a)
-> (a -> a -> a)
-> (a -> a -> a)
-> (a -> a)
-> (a -> a)
-> (a -> a)
-> (Integer -> a)
-> Num a
$c+ :: Vector1 -> Vector1 -> Vector1
+ :: Vector1 -> Vector1 -> Vector1
$c- :: Vector1 -> Vector1 -> Vector1
- :: Vector1 -> Vector1 -> Vector1
$c* :: Vector1 -> Vector1 -> Vector1
* :: Vector1 -> Vector1 -> Vector1
$cnegate :: Vector1 -> Vector1
negate :: Vector1 -> Vector1
$cabs :: Vector1 -> Vector1
abs :: Vector1 -> Vector1
$csignum :: Vector1 -> Vector1
signum :: Vector1 -> Vector1
$cfromInteger :: Integer -> Vector1
fromInteger :: Integer -> Vector1
Num, Num Vector1
Num Vector1 =>
(Vector1 -> Vector1 -> Vector1)
-> (Vector1 -> Vector1)
-> (Rational -> Vector1)
-> Fractional Vector1
Rational -> Vector1
Vector1 -> Vector1
Vector1 -> Vector1 -> Vector1
forall a.
Num a =>
(a -> a -> a) -> (a -> a) -> (Rational -> a) -> Fractional a
$c/ :: Vector1 -> Vector1 -> Vector1
/ :: Vector1 -> Vector1 -> Vector1
$crecip :: Vector1 -> Vector1
recip :: Vector1 -> Vector1
$cfromRational :: Rational -> Vector1
fromRational :: Rational -> Vector1
Fractional)

instance BasicVector Vector1 where
  vmap :: (Scalar -> Scalar) -> Vector1 -> Vector1
vmap  Scalar -> Scalar
f (Vector1 Scalar
x )              = Scalar -> Vector1
Vector1 (Scalar -> Scalar
f Scalar
x)
  vzip :: (Scalar -> Scalar -> Scalar) -> Vector1 -> Vector1 -> Vector1
vzip  Scalar -> Scalar -> Scalar
f (Vector1 Scalar
x1) (Vector1 Scalar
x2) = Scalar -> Vector1
Vector1 (Scalar -> Scalar -> Scalar
f Scalar
x1 Scalar
x2)
  vfold :: (Scalar -> Scalar -> Scalar) -> Vector1 -> Scalar
vfold Scalar -> Scalar -> Scalar
_ (Vector1 Scalar
x )              = Scalar
x

  vpack :: [Scalar] -> Maybe Vector1
vpack (Scalar
x:[Scalar]
_) = Vector1 -> Maybe Vector1
forall a. a -> Maybe a
Just (Vector1 -> Maybe Vector1) -> Vector1 -> Maybe Vector1
forall a b. (a -> b) -> a -> b
$ Scalar -> Vector1
Vector1 Scalar
x
  vpack [Scalar]
_     = Maybe Vector1
forall a. Maybe a
Nothing

  vunpack :: Vector1 -> [Scalar]
vunpack (Vector1 Scalar
x) = [Scalar
x]

  vpromote :: Scalar -> Vector1
vpromote Scalar
x = Scalar -> Vector1
Vector1 Scalar
x

instance Vector Vector1 where