ratioRoot :: Floating a => a -> [a] -> a
ratioRoot _ [ _ ] = 0
ratioRoot r options =
    1 / fromIntegral (length options - 1) * sum
        [ abs (x - y)**r
        | x <- options
        , y <- options
        ]

test :: ([Double] -> Double) -> [Double] -> IO ()
test measure options = do
    putStrLn $ "Option set:\n" ++ show options
    putStrLn $ "Freedom:\n" ++ show (measure options) ++ "\n"

main :: IO ()
main = do

    putStrLn "Ratio-root measure with r = 0.5\n"
    test (ratioRoot 0.5) [ 16.0, 22.0, 28.0 ]
    test (ratioRoot 0.5) [ 16.0, 16.1, 27.9, 28.0 ]

    putStrLn "Ratio-root measure with r = 0.99\n"
    test (ratioRoot 0.99) [ 16.0, 22.0, 28.0 ]
    test (ratioRoot 0.99) [ 16.0, 16.1, 27.9, 28.0 ]

    putStrLn "Ratio-root measure with r = 1\n"
    test (ratioRoot 1) [ 16.0, 22.0, 28.0 ]
    test (ratioRoot 1) [ 16.0, 16.1, 27.9, 28.0 ]
