{- Some functions that should be in the Prelude
   unless they are already there and I didn't found them. -}

module Useful where

import Data.Tuple.HT (swap, )


(^!) :: Num a => a -> Int -> a
(^!) = (^)

functionToGraph :: [a] -> (a -> a) -> [(a,a)]
functionToGraph args f = map swap $ attachKey f args

attachKey :: (a -> b) -> [a] -> [(b,a)]
attachKey key = map (\x -> (key x, x))

scalarProduct :: Num a => [a] -> [a] -> a
scalarProduct x y = sum (zipWith (*) x y)

