[Haskell-cafe] Way to implement toFloat :: (Num a) => a -> Float

Ben Foppa benjamin.foppa at gmail.com
Thu Dec 12 19:34:13 UTC 2013


> toRational :: Real a => a -> Rational

This, combined with

fromRational :: Fractional a => Rational -> a

forms realToFrac :: (Real a, Fractional b) => a -> b


On Thu, Dec 12, 2013 at 2:29 PM, Niklas Haas <haskell at nand.wakku.to> wrote:

> On Thu, 12 Dec 2013 20:19:35 +0100, EatsKittens <
> temporalabstraction at gmail.com> wrote:
> > Is there a way to add a method to a typeclass like num to implement this
> > concept? A function that converts any number to floats?
> Non-text part: text/html
> > _______________________________________________
> > Haskell-Cafe mailing list
> > Haskell-Cafe at haskell.org
> > http://www.haskell.org/mailman/listinfo/haskell-cafe
>
> The typeclass Real has this in a slightly different form:
>
> toRational :: Real a => a -> Rational
>
> You can use fromRational :: Rational -> Float together with this to
> implement your function.
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20131212/3a866f9c/attachment.html>


More information about the Haskell-Cafe mailing list