[Haskell-beginners] Netwire fromRational

Ertugrul Söylemez es at ertes.de
Thu Oct 4 03:19:17 CEST 2012


Nathan Hüsken <nathan.huesken at posteo.de> wrote:

> Let me simplify the example:
>
> testW1 :: WireP () Double
> testW1 = pure 1.0
>
> testW2 :: WireP () Double
> testW2 = 1.0
>
> main = do
>   let (res, _) = stepWire 1.0 () testW
>   putStrLn $ show res
>
> (set testW to testW1 or testW2).
> When I test this with testW=testW2 I see that "fromRational" is called
> which converts a Rational (=Ration Integer) to a WireP () Double (I
> tested this by adding a "trace" to the fromRational
> Control/Wire/Classes.hs).
> This means the "1.0" is converted to a Rational and then back to a
> WireP () Double, correct?

That's incorrect.  There is absolutely no difference between the two
except perhaps some RULE pragmas might apply.  Let me elaborate.  For
Wire the 'fromRational' function is defined like this:

    fromRational = pure . fromRational

Then the following holds:

    -- Using Double's Fractional instance:
    pure 1.0 = pure (fromRational (1 % 1))

    -- Using Wire's Fractional instance:
    1.0 = (pure . fromRational) (1 % 1)
        = pure (fromRational (1 % 1))


Greets,
Ertugrul

-- 
Not to be or to be and (not to be or to be and (not to be or to be and
(not to be or to be and ... that is the list monad.
-------------- next part --------------
A non-text attachment was scrubbed...
Name: signature.asc
Type: application/pgp-signature
Size: 836 bytes
Desc: not available
URL: <http://www.haskell.org/pipermail/beginners/attachments/20121004/04afb9a9/attachment.pgp>


More information about the Beginners mailing list