The square root of rational

Given the following Rational:

Prelude> x
1 % 2

I tried to take my square root:

Prelude> sqrt x

<interactive>:14:1:
    No instance for (Floating Rational) arising from a use of `sqrt'
    In the expression: sqrt x
    In an equation for `it': it = sqrt x

I read this conversion math article . But I have not seen how to convert between Rational and Floating.

How can i do this?

+4
source share
1 answer

You can use fromRational,

fromRational :: Fractional a => Rational -> a

or general purpose realToFrac,

realToFrac :: (Real a, Fractional b) => a -> b
+6
source

All Articles