diff options
author | Alberto Ruiz <aruiz@um.es> | 2007-06-22 17:33:17 +0000 |
---|---|---|
committer | Alberto Ruiz <aruiz@um.es> | 2007-06-22 17:33:17 +0000 |
commit | 978e6d038239af50d70bae2c303f4e45b1879b7a (patch) | |
tree | 571b2060f388d0693820f808b40089acb100a5d9 /lib/Data/Packed/Internal/Common.hs | |
parent | 989bdf7e88c13500bd1986dcde36f6cc4f467efb (diff) |
refactoring
Diffstat (limited to 'lib/Data/Packed/Internal/Common.hs')
-rw-r--r-- | lib/Data/Packed/Internal/Common.hs | 7 |
1 files changed, 7 insertions, 0 deletions
diff --git a/lib/Data/Packed/Internal/Common.hs b/lib/Data/Packed/Internal/Common.hs index bdd7f34..1bfed6d 100644 --- a/lib/Data/Packed/Internal/Common.hs +++ b/lib/Data/Packed/Internal/Common.hs | |||
@@ -40,6 +40,7 @@ instance (Storable a, RealFloat a) => Storable (Complex a) where -- | |||
40 | poke p (a :+ b) = pokeArray (castPtr p) [a,b] -- | 40 | poke p (a :+ b) = pokeArray (castPtr p) [a,b] -- |
41 | ---------------------------------------------------------------------- | 41 | ---------------------------------------------------------------------- |
42 | 42 | ||
43 | on :: (a -> a -> b) -> (t -> a) -> t -> t -> b | ||
43 | on f g = \x y -> f (g x) (g y) | 44 | on f g = \x y -> f (g x) (g y) |
44 | 45 | ||
45 | partit :: Int -> [a] -> [[a]] | 46 | partit :: Int -> [a] -> [[a]] |
@@ -54,12 +55,14 @@ common f = commonval . map f where | |||
54 | commonval [a] = Just a | 55 | commonval [a] = Just a |
55 | commonval (a:b:xs) = if a==b then commonval (b:xs) else Nothing | 56 | commonval (a:b:xs) = if a==b then commonval (b:xs) else Nothing |
56 | 57 | ||
58 | xor :: Bool -> Bool -> Bool | ||
57 | xor a b = a && not b || b && not a | 59 | xor a b = a && not b || b && not a |
58 | 60 | ||
59 | (//) :: x -> (x -> y) -> y | 61 | (//) :: x -> (x -> y) -> y |
60 | infixl 0 // | 62 | infixl 0 // |
61 | (//) = flip ($) | 63 | (//) = flip ($) |
62 | 64 | ||
65 | errorCode :: Int -> String | ||
63 | errorCode 1000 = "bad size" | 66 | errorCode 1000 = "bad size" |
64 | errorCode 1001 = "bad function code" | 67 | errorCode 1001 = "bad function code" |
65 | errorCode 1002 = "memory problem" | 68 | errorCode 1002 = "memory problem" |
@@ -68,6 +71,7 @@ errorCode 1004 = "singular" | |||
68 | errorCode 1005 = "didn't converge" | 71 | errorCode 1005 = "didn't converge" |
69 | errorCode n = "code "++show n | 72 | errorCode n = "code "++show n |
70 | 73 | ||
74 | check :: String -> [Vector a] -> IO Int -> IO () | ||
71 | check msg ls f = do | 75 | check msg ls f = do |
72 | err <- f | 76 | err <- f |
73 | when (err/=0) (error (msg++": "++errorCode err)) | 77 | when (err/=0) (error (msg++": "++errorCode err)) |
@@ -77,7 +81,10 @@ check msg ls f = do | |||
77 | class (Storable a, Typeable a) => Field a | 81 | class (Storable a, Typeable a) => Field a |
78 | instance (Storable a, Typeable a) => Field a | 82 | instance (Storable a, Typeable a) => Field a |
79 | 83 | ||
84 | isReal :: (Data.Typeable.Typeable a) => (t -> a) -> t -> Bool | ||
80 | isReal w x = typeOf (undefined :: Double) == typeOf (w x) | 85 | isReal w x = typeOf (undefined :: Double) == typeOf (w x) |
86 | |||
87 | isComp :: (Data.Typeable.Typeable a) => (t -> a) -> t -> Bool | ||
81 | isComp w x = typeOf (undefined :: Complex Double) == typeOf (w x) | 88 | isComp w x = typeOf (undefined :: Complex Double) == typeOf (w x) |
82 | 89 | ||
83 | scast :: forall a . forall b . (Typeable a, Typeable b) => a -> b | 90 | scast :: forall a . forall b . (Typeable a, Typeable b) => a -> b |