[Haskell-beginners] Double usage of a wire (arrow)
Ertugrul Söylemez
es at ertes.de
Mon Nov 5 17:22:48 CET 2012
Nathan Hüsken <nathan.huesken at posteo.de> wrote:
> If I double use an arrow (in this example a wire from netwire) like
> this:
>
> objectWire :: WireP [Collision] Object
> objectWire = (Object <$> integral_ initPos) . speedWire <*> speedWire
>
> will it be double evaluated, or can the compiler optimize this to
> evaluate speedWire only once?
It will be double-evaluated. To prevent this you can use the Arrow
interface:
proc x' -> do
x <- speedWire -< x'
{- ... use x ... -}
However, in WireP it's guaranteed that you get the same result, so for
code conciseness you can still have speedWire twice, if sacrificing some
speed is not too big an issue.
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/20121105/018fec91/attachment.pgp>
More information about the Beginners
mailing list