-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Easy-to-use reasonable way of emulating approximate in Haskell. -- -- Please see the README on GitHub at -- https://github.com/n-kishaloy/approx#readme @package approx @version 0.1.0.1 -- | The library is created to allow for a easy-to-use reasonable way of -- emulating approx in Haskell. The codes are all in pure Haskell. -- The idea is to have a natural mathematical feel in writing code, with -- operators which just works when working with Double and Float and -- their composite types like lists, vectors etc. -- -- The Approx module defines 2 operators =~ and -- /~, which are for checking nearly equal to and -- not nearly equal to respectively. -- -- Both the operators =~ and /~ are put under the class -- Approx. -- -- At least one of the operators have to be defined and the other gets -- automatically defined. -- -- The library already defines the functions for some of the basic / -- common types. -- -- For types where Eq is defined like Char, Bool, Int, Day, -- Text the approx is simply replaced with ==. -- -- For Float and Double, the following formula is used, -- --
--   if max ( |x|, |y| ) < epsilon_Zero
--   then True
--   else 
--     if |x - y| / max ( |x|, |y| ) < epsilon_Eq
--     then True
--     else False
--   
-- -- The motivation for defining Approx for classes for which Eq is also -- defined is to allow for composite types where both Eq and Approx would -- be present. For example, the following code evaluates to -- True, even though the tuple is of type -- (Int,Double,Text,[Int],[[Char]],[Double]). -- --
--   ((2,5.35,"happ",[1,2],["ret","we"],[6.78,3.5]) 
--       :: (Int,Double,Text,[Int],[[Char]],[Double])) 
--       
--       =~ (2,5.35,"happ",[1,2],["ret","we"],[6.78,3.5])
--   
-- -- For UTCTime, the approx operator checks for equality to the nearest -- minute. The following expression evaluates to True. -- --
--   (parseTimeM True defaultTimeLocale "%Y-%m-%d %H:%M:%S" "2020-01-15 15:02:15" 
--       :: Maybe UTCTime) 
--   
--       =~ parseTimeM True defaultTimeLocale "%Y-%m-%d %H:%M:%S" "2020-01-15 15:01:50"
--   
-- -- The library also provides approx for Complex and common structures -- like List, Boxed and Unboxed Vector, Hashmap, Tuples and -- Maybe. For all lists, tuples, hashmaps and vectors, the -- approximation is checked right down to the elements and the order for -- lists and vectors are important. -- -- For lists, only finite lists are supported. Any use of infinite lists -- would cause a runtime error. -- -- There are addtional functions inRange, safeInRange and -- inTol, which checks for values within Ranges either -- explictily defined as in inRange and safeInRange -- or through tolerances as in inTol. -- -- You may see the github repository at -- https://github.com/n-kishaloy/approx module Data.Approx -- | The class Approx defines 2 operators =~ and -- /~, which are for checking nearly equal to and -- not nearly equal to respectively. class Approx a (=~) :: Approx a => a -> a -> Bool (/~) :: Approx a => a -> a -> Bool infix 4 =~ infix 4 /~ -- |
--   inRange (u,v) x = check if x is inside the range (u,v)
--   
-- -- Note: The function assumes u < v. This is done to -- ensure speed of operations. Use safeInRange, otherwise. inRange :: Ord a => (a, a) -> a -> Bool infix 4 `inRange` -- |
--   safeInRange (u,v) x = check if x is inside the range (u,v)
--   
-- -- Note: The function works even if u>v. However, it has addtional -- checks and is more expensive. Use only if you are not sure that u < -- v for your use-case. safeInRange :: Ord a => (a, a) -> a -> Bool infix 4 `safeInRange` -- |
--   inTol t p x = inRange (p - t, p + t) x
--   
-- -- The Function checks if x is close to p -- within a tolerance band t. Please ensure -- t is positive or there would be -- incorrect results. inTol :: (Num a, Ord a) => a -> a -> a -> Bool infix 4 `inTol` instance Data.Approx.Approx Data.Time.Calendar.Days.Day instance Data.Approx.Approx GHC.Types.Char instance Data.Approx.Approx GHC.Types.Bool instance Data.Approx.Approx Data.Text.Internal.Text instance Data.Approx.Approx GHC.Types.Int instance Data.Approx.Approx GHC.Integer.Type.Integer instance Data.Approx.Approx Data.Time.Clock.Internal.UTCTime.UTCTime instance Data.Approx.Approx a => Data.Approx.Approx (Data.Complex.Complex a) instance Data.Approx.Approx GHC.Types.Float instance Data.Approx.Approx GHC.Types.Double instance Data.Approx.Approx a => Data.Approx.Approx (GHC.Maybe.Maybe a) instance Data.Approx.Approx a => Data.Approx.Approx [a] instance (Data.Approx.Approx a, Data.Approx.Approx b) => Data.Approx.Approx (a, b) instance (Data.Approx.Approx a, Data.Approx.Approx b, Data.Approx.Approx c) => Data.Approx.Approx (a, b, c) instance (Data.Approx.Approx a, Data.Approx.Approx b, Data.Approx.Approx c, Data.Approx.Approx d) => Data.Approx.Approx (a, b, c, d) instance (Data.Approx.Approx a, Data.Approx.Approx b, Data.Approx.Approx c, Data.Approx.Approx d, Data.Approx.Approx e) => Data.Approx.Approx (a, b, c, d, e) instance (Data.Approx.Approx a, Data.Approx.Approx b, Data.Approx.Approx c, Data.Approx.Approx d, Data.Approx.Approx e, Data.Approx.Approx f) => Data.Approx.Approx (a, b, c, d, e, f) instance (Data.Approx.Approx a, Data.Approx.Approx b, Data.Approx.Approx c, Data.Approx.Approx d, Data.Approx.Approx e, Data.Approx.Approx f, Data.Approx.Approx g) => Data.Approx.Approx (a, b, c, d, e, f, g) instance (Data.Approx.Approx a, Data.Approx.Approx b, Data.Approx.Approx c, Data.Approx.Approx d, Data.Approx.Approx e, Data.Approx.Approx f, Data.Approx.Approx g, Data.Approx.Approx h) => Data.Approx.Approx (a, b, c, d, e, f, g, h) instance (Data.Approx.Approx a, Data.Approx.Approx b, Data.Approx.Approx c, Data.Approx.Approx d, Data.Approx.Approx e, Data.Approx.Approx f, Data.Approx.Approx g, Data.Approx.Approx h, Data.Approx.Approx i) => Data.Approx.Approx (a, b, c, d, e, f, g, h, i) instance (Data.Approx.Approx a, Data.Approx.Approx b, Data.Approx.Approx c, Data.Approx.Approx d, Data.Approx.Approx e, Data.Approx.Approx f, Data.Approx.Approx g, Data.Approx.Approx h, Data.Approx.Approx i, Data.Approx.Approx j) => Data.Approx.Approx (a, b, c, d, e, f, g, h, i, j) instance (Data.Approx.Approx a, Data.Approx.Approx b, Data.Approx.Approx c, Data.Approx.Approx d, Data.Approx.Approx e, Data.Approx.Approx f, Data.Approx.Approx g, Data.Approx.Approx h, Data.Approx.Approx i, Data.Approx.Approx j, Data.Approx.Approx k) => Data.Approx.Approx (a, b, c, d, e, f, g, h, i, j, k) instance (Data.Vector.Unboxed.Base.Unbox a, Data.Approx.Approx a) => Data.Approx.Approx (Data.Vector.Unboxed.Base.Vector a) instance Data.Approx.Approx a => Data.Approx.Approx (Data.Vector.Vector a) instance (GHC.Classes.Eq a, Data.Hashable.Class.Hashable a, Data.Approx.Approx b) => Data.Approx.Approx (Data.HashMap.Internal.HashMap a b)