Допис з розмови
Avoid unnecessary evaluations
Path: g2news1.google.com!news1.google.com!news2.google.com!news.glorb.com!feeder.erje.net!newsfeed01.sul.t-online.de!t-online.de!fu-berlin.de!uni-berlin.de!news.dfncis.de!not-for-mail
From: Frank Poettgen <Frank.Poett...@Post.RxWyTxH-AyAzCyHzEyN.de>
Newsgroups: comp.lang.haskell
Subject: Avoid unnecessary evaluations
Date: Thu, 28 May 2009 15:36:12 +0200
Lines: 11
Message-ID: <787ia8F1h6d4hU1@mid.dfncis.de>
Mime-Version: 1.0
Content-Type: text/plain; charset=ISO-8859-15; format=flowed
Content-Transfer-Encoding: 7bit
X-Trace: news.dfncis.de iDBZdsc9DSFYPXkNokBbQANqSou6BUcL9Pv4wVrCTV3W8EQZTQqezL4atD
Cancel-Lock: sha1:FRQ6l4lmx4GG0QsJJFqBXFBukew=
User-Agent: Thunderbird 2.0.0.18 (Windows/20081105)
Assume that the evaluation of a function 'expensive' takes a lot of
time. Hence I want to avoid unnecessary evaluations of 'expensive'.
expensive :: Int -> (Int,Int)
expensive x = (x,x)
f :: Int -> Int
f x = fst (expensive x) + snd (expensive x)
Will 'expensive x' be evaluated twice to compute 'f x'?
If so, how can I avoid it?