Група, до якої ви додаєте допис, - група Usenet. Відтак, будь-хто в Інтернеті бачитиме вашу електронну адресу.
Вашу відповідь не було надіслано.
Ваш допис надіслано
Групи новин: comp.lang.haskell
Від: Florian Kreidler <m...@privacy.net>
Дата: 28 May 2009 16:11:42 +0200
Місцевий час: Чт 28 Тра 2009 17:11
Тема: Re: Avoid unnecessary evaluations
Frank Poettgen <Frank.Poett...@Post.RxWyTxH-AyAzCyHzEyN.de> schrieb:
> Assume that the evaluation of a function 'expensive' takes a lot of That will depend on your compiler. Some compilers do common > time. Hence I want to avoid unnecessary evaluations of 'expensive'. > expensive :: Int -> (Int,Int) > f :: Int -> Int > Will 'expensive x' be evaluated twice to compute 'f x'? subexpression elimination, others don't. The reason is that this transformation can sometimes introduce space leaks. In your case it wouldn't be dangerous, but you cannot rely on your compiler recognizing this. > If so, how can I avoid it? Rewrite the function by hand: f x = fst e + snd e where e = expensive or, using pattern matching, f x = l + r where (l, r) = expensive x or, more compact but less comprehensible, f = uncurry (+) . expensive Ви мусите увійти перед публікацією повідомлень.
Аби надіслати допис, будь ласка, спочатку приєднайтеся до цієї групи.
Будь ласка, поновіть своє прізвисько на сторінці налаштування передплати перед тим, як надіслати свій допис.
У вас немає права надсилання дописів до цієї групи.
| ||||||||||||||