    {-# LANGUAGE FlexibleContexts #-}
    {-# LANGUAGE FlexibleInstances #-}
    {-# LANGUAGE MultiParamTypeClasses #-}
    {-# LANGUAGE UndecidableInstances #-}

    {-# OPTIONS_GHC -fno-warn-simplifiable-class-constraints #-}

    module Data.Random.Distribution.Pareto where

    import Data.Random

    pareto :: Distribution Pareto a => a -> a -> RVar a
    pareto :: forall a. Distribution Pareto a => a -> a -> RVar a
    pareto a
    xM a
    a = Pareto a -> RVar a
    forall (d :: * -> *) t. Distribution d t => d t -> RVar t
    rvar (a -> a -> Pareto a
    forall a. a -> a -> Pareto a
    Pareto a
    xM a
    a)

    paretoT :: Distribution Pareto a => a -> a -> RVarT m a
    paretoT :: forall a (m :: * -> *).
    Distribution Pareto a =>
    a -> a -> RVarT m a
    paretoT a
    xM a
    a = Pareto a -> RVarT m a
    forall (n :: * -> *). Pareto a -> RVarT n a
    forall (d :: * -> *) t (n :: * -> *).
    Distribution d t =>
    d t -> RVarT n t
    rvarT (a -> a -> Pareto a
    forall a. a -> a -> Pareto a
    Pareto a
    xM a
    a)

    data Pareto a = Pareto !a !a

    instance (Floating a, Distribution StdUniform a) => Distribution Pareto a where
        rvarT :: forall (n :: * -> *). Pareto a -> RVarT n a
    rvarT (Pareto a
    xM a
    a) = do
            u <- RVarT n a
    forall a (m :: * -> *). Distribution StdUniform a => RVarT m a
    stdUniformT
            return (xM / (1 - u) ** recip a)

    instance (Real a, Distribution Pareto a) => CDF Pareto a where
        cdf :: Pareto a -> a -> Double
    cdf (Pareto a
    xM a
    a) a
    x
             | a
    x a -> a -> Bool
    forall a. Ord a => a -> a -> Bool
    >= a
    xM      = Double
    1 Double -> Double -> Double
    forall a. Num a => a -> a -> a
    - (a -> Double
    forall a b. (Real a, Fractional b) => a -> b
    realToFrac a
    xM Double -> Double -> Double
    forall a. Fractional a => a -> a -> a
    / a -> Double
    forall a b. (Real a, Fractional b) => a -> b
    realToFrac a
    x) Double -> Double -> Double
    forall a. Floating a => a -> a -> a
    ** a -> Double
    forall a b. (Real a, Fractional b) => a -> b
    realToFrac a
    a
             | Bool
    otherwise    = Double
    0