X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=src%2FTwoTuple.hs;h=daeb6e41f8cdbbbe43e11139236dbc88f5955c18;hb=ff83c063ad5cdb1bf9476678a010aa0cfb782a8f;hp=8493114ed7cac3dcc956a801127e5b43eca0efef;hpb=06c8df4932b9a46e48b3fc99c3bc44e787b182fc;p=numerical-analysis.git diff --git a/src/TwoTuple.hs b/src/TwoTuple.hs index 8493114..daeb6e4 100644 --- a/src/TwoTuple.hs +++ b/src/TwoTuple.hs @@ -4,13 +4,22 @@ module TwoTuple where +import Vector + + data TwoTuple a = TwoTuple a a deriving (Eq, Show) instance Functor TwoTuple where f `fmap` (TwoTuple x1 y1) = TwoTuple (f x1) (f y1) +instance (RealFloat a) => Vector (TwoTuple a) where + -- The standard Euclidean 2-norm. We need RealFloat for the square + -- root. + norm (TwoTuple x1 y1) = fromRational $ toRational (sqrt(x1^2 + y1^2)) +-- | It's not correct to use Num here, but I really don't want to have +-- to define my own addition and subtraction. instance Num a => Num (TwoTuple a) where -- Standard componentwise addition. (TwoTuple x1 y1) + (TwoTuple x2 y2) =