Imposing the Edges Later 75
Here’s what wikipedia has to say about lazy evaluation:
The benefits of lazy evaluation include: performance increases due to avoiding unnecessary calculations, avoiding error conditions in the evaluation of compound expressions, the ability to construct infinite data structures, and the ability to define control structures as regular functions rather than built-in primitives.
It’s all true, but I think it misses a point. One of the nicest things about lazy evaluation is that it enables a different form of abstraction. Take a look at this code. It computes the Mandelbrot Set. There are many ways to code up this algorithm, but the code I just linked to is very typical – it’s a doubly nested loop which iterates over a specific rectangle in the complex plane. It’s hard to see anything that’s awkward about its iteration strategy in a procedural language – the algorithm does require starting and ending points in the plane.
Let’s look at a different way of approaching this. Here’s part of a Mandelbrot Set generator in Haskell:
mandelbrot :: Double -> [[Int]]
mandelbrot incrementSize =
[[ escapeIterations $ translate offset . translate (x,y) . mandel
| x <- increments]
| y <- increments]
where increments = [0.0, incrementSize .. ]
window :: (Int, Int) -> (Int, Int) -> [[a]] -> [[a]]
window (x0, x1) (y0, y1) = range y0 y1 . map (range x0 x1)
where range m n = take (n-m) . drop m
The interesting bit is the mandelbrot
function. It contains a doubly-nested list comprehension which, essentially, mimics the behavior of a doubly-nested loop in the procedural algorithm. However, there is one interesting difference. This list comprehension actually represents the mandelbrot computation across a full quarter of the infinite plane – it goes from zero to infinity in x and y. All we have to do is pass it an increment size and it is configured to create that grid. If we want to zoom in to a particular place in the Mandelbrot Set, we can use the window
function like this:
-- compute the mandelbrot from (10,10) inclusive to
-- (20,20) exclusive with an increment of 0.05
window (10, 20) (10, 20) $ mandelbrot 0.05
The trick to this code is in window
’s range
computation. It takes a starting position, an ending position, and a list and it drops all of the elements of the list before the starting position, without evaluating them, and then it takes, from the front of the new list, end - start
elements, giving us a sub-range from the original list. When that elements of that sub-list are evaluated, the computation for each point in the window occurs.
This code yields the computation that we want and the neat thing is, we are really only computing the piece we specified with window
. We’ve essentially formed a general computation and imposed the edges later.
Looking back now at the imperative mandelbrot code, it’s easy to see that it was, in a way, mixing two concerns. The code which determined the range was mixed with the code which generated the set. Laziness allows us to separate the two concerns.
Note: There are much more direct ways of computing the Mandelbrot Set in Haskell. Here’s one which is particularly brief.
As a Haskell fan I’m searching for examples where the lazy-by-default approach of Haskell beats other like Python’s iterators… the only one I’m aware of is when you use the “tying-the-knot” techniques which has more to do with performance than with good software engineering practices…
Cristiano: Are you talking about this? http://www.haskell.org/haskellwiki/Tying_the_Knot
Michael,
Interesting read, indeed lazy eval is extremely useful for all forms of culling.
I am personally very interested in picking up a purely functional lazy language to do some experimenting in.
For my personal enjoyment I am fanatical about seeing my results so I did a lot of hobby coding with C++ and OpenGL.
Which functional language will be easiest to get me drawing nice graphical things?
Regards Dawid
Sorry wrong email
Dawid: I think Clean and Miranda are fully lazy also, but Haskell has the best support and it has a growing community around it.
If you like graphics work, consider this book: http://www.amazon.com/Haskell-School-Expression-Functional-Programming/dp/0521644089/ It introduces Haskell from the beginning using graphics and gaming examples. You will probably need at least one other introductory Haskell book also to round out the edges.
> Laziness allows us to separate the two concerns.
Indeed, see also John Hughes : http://www.cs.chalmers.se/~rjmh/Papers/whyfp.pdf
“Since this method of evaluation runs f as little as possible, it is called “lazy evaluation”. It makes it practical to modularise a program as a generator which constructs a large number of possible answers, and a selector which chooses the appropriate one. [...] Lazy evaluation is perhaps the most powerful tool for modularisation in the functional programmer’s repertoire.”
window (10000010, 10000010) (10000015, 10000015) $ (mandelbrot 1.0)
?window (10, 20) (10, 20) 0.05 $ mandelbrot
?Eli: That just returns an empty list. Each pair is a range along a dimension, not a coordinate. Are you making a point about the cost of dropping all of those list elements?
Not quite sure what you are getting at with (2). If it’s the fact that we could pass the computation for single points to iteration code, then I agree that is a different way of factoring this, but it couples the gridding and constraints in the window function.
Let me clarify the two points I’m making:
window
function, but that’s pretty minor since it is very straightforward to do the same in a strict language.Combine the two points (avoid the cost for dropping items, abstract the resolution), and the code that you end up with is going to be nearly identical in either a lazy or a strict language. That’s why I started by saying that this is not a good example (of using a lazy language).
Just to balance things, let me point out one big advantage of a lazy language. A feature that is desirable in many languages is list comprehension. Now the thing is how do you deal with list comprehension vs iteration? In Python, for example, if you use
for i in range(1,100000000)
, it will actually (try to) build the huge list and then perform the iteration. As a result, strict languages might have one syntax for lists and another for loops. As another example, in PLT Scheme there is anin-range
function that instead of generating a list, it generates a “sequence” value, which can be used in afor
expression (and easily convertible into a list, but that’s irrelevant).But in a lazy language a list is the same as a specification of an iteration, and the equivalent of such a
range
function can be used either as a list or as a specification for a loop and you don’t lose any efficiency. The obvious way to see this is to see how the language deals with infinite iterations: in Pythonrange
produces a finite range, in PLT Scheme there is ain-naturals
function but it produces one of these sequence values rather than a list—but only in Haskell you have the same value representing both an infinite iteration and a list.(BTW, gravatar-enabled comments are cute, but the interface should remember my email for later posts…)
It’s easier and faster to handle the separation of concerns on a slightly different level: (1) computing mandelbrot value for a single point and (2) computing some value for all points on a grid. This does not even require laziness, just higher order functions.
let map2d fn xs ys = [[fn x y | x <- xs] | y <- ys]
map2d mandelpoint [x0, x0+step .. x1] [y0, y0+step .. y1]
Using an infinite list isn’t a good idea here. Like Eli argued, computing the values far away from origin is going to be super slow due to drop taking O(x0 times y0) time. Some abstraction cost may be acceptable, but jumping from O(1) to O(N times M) is not.
http://www.haskell.org/haskellwiki/Tying_the_Knot should be better knowned.
very nice website i really like the design and also the great information. thanks
http://www.emicsoft.com/3gp-converter.html
what a u showing off?
good
People die for iphone 4 white is understandable, isn’t it? The reason is quite simple, We all want to be differnt!
This is a good post. This post give truly quality information.I’m definitely going to look into it.Really very useful tips are provided here.thank you so much.Keep up the good works.
cosmetic surgeon kansas
With the right tool, you can easily burn mp4 to dvd and itunes to dvd. Also, you can use drm removal tool to remove drm protection from itunes, zune, amazon legally. wmv to dvd, mov to dvd, mp4 to dvd, itunes to dvd
thanks for Moncler Jackets || Christian louboutin UK || Moncler coats || Christian louboutin shoes || Christian louboutin pumps your post!
very nice website i really like the design and also the great information. thanksaccounting services
I think that programmers communicate with structure as much as they communicate with names. It’s the body-language of their code.
JAY Follow laptop accessories the detail tips below, you can increase the laptop battery life of a year or more. 1. The laptop battery first thing you should care about the
I’m pretty fond of it. I also have a one-liner for Laplace expansion of determinants and few-liners for a number of other linear algebra algorithms based on this zipper I designed.
I wouldn’t use it for serious numerical work. Then again, I wouldn’t use Haskell for that in the first place.
As a matter of truth, you will find some factors for individuals to decide the value of the rolex watches. In order to get precious rolexes watches for collecting, you’ll want to pay attention to the following aspects. At 1st, you need to judge the amount of the fake rolex. The amount of the Rolex DateJust watches existing in rolex watches the world is crucial. If Rolex Daytona is exclusive, and it has a small amount within the world, Swiss Replica Watch is going to become far more useful replica watches with the development of years. A widespread Discount Watches just isn’t worth to collect. Useful Rolex Day Date are available in tiny amounts. The distinct looks of these designer fake watches are extremely unique. In most models, the face dials generally feature a layered design. This makes the brand genuinely intriguing and attractive. The cheap watches are created from a few of the finest supplies utilized in contemporary Breitling Watches generating. Copy Watches supplies incorporate solid Fake Watches state and refined stainless steel, diamonds, reinforced crystals and other precious stones. In some models, the bracelets consist of a mixture of gold and stainless steel while a much more casual leather band is also available. The Omega Watches of Raymond Weil are mysterious and intriguing on account of the special textured layering of the front faces. Do not buy sport Cartier Watches if you are an office lady. The replica watches are an individual belonging that represents the taste and the style of a person. Imitation Watches will be easy for you if you have already known about yourself well. At last, we bet you can find the ideal women’s replica watches uk for the women in your life as long as you do research correctly.
We are the professional clothing manufacturer and clothing supplier, so we manufacture kinds of custom clothing manufacturer. welcome you to come to our china clothing manufacturer and clothing factory.
Buy $10 Replica Designer Sunglasses
I wouldn’t use it for serious numerical work. Then again, I wouldn’t use Haskell for that in the first place.
Thank you very much for this article and blog.I like its and as to me it’s good job.
Any lady with wholesale beads wedding on the brain will be dropping not so faint hints beside the wholesale jewelry beads,wholesale beads way so pay consideration when you’re receiving prepared to pop wholesale pandora beads the query. You can also seem at the jewelry she already owns to get an clue of her chic, especially regarding what type of wholesale fashion jewelry metal she loves. Keep in mind that she will be got up in this ring for the rest of her life so make definite to choose something that suits her personality.
This was a really fantastic post that I really do appreciate. This is something that is really amazing and interesting to me to say the least. Social Network
Gossip sur les bijoux et les montres replique montres de luxe la mode des plus classiques, voir le CD en noir réplique montre rolex pour montrer la force et de caractère, partout dans le vague replique de montre noire en conformité avec l’horloge ma?tre, transformée en aval montres repliques de la classique pour hommes. n’importe.Selon vague “Black à l’alambic” série de montres montres de luxe suisses à l’aide mouvement à quartz et un rendement supérieur. Caisse noire, cadran noir et solide en acier inoxydable avec un bracelet noir brillant, réplique montre Omega peut se produire danspar rapport à ceux bijoux finement con?u montres a publié un éloge et le doute
A bad beginning makes a bad ending. A bird in the hand is worth than two in the bush. A year’s plan starts with
spring. Bad news has wings. Better to ask the way than go astray. By reading we enrich the mind, by conversation we
polish it. Custom makes all things easy. He is not fit to command others that cannot command himself. He laughs best
who laughs last. tiffany and co outlet
Wow, this is too cool. I am very like it, Thank you for sharing
a Seobaglyak igazán éjszaka érzik elemükben magukat. Szinte ”kétlaki” életet élnek. A Seobaglyak éjszaka sokkal éberebbek, és agresszívabbak, olyannyira, hogy olyankor saját fajtársaikat tartják a legnagyobb ellenségeiknek.
belstaff Boots purchase for a lot of women on Belstaff UK Outlet
store online. it is possible to buy belstaff Trailmaster boots, belstaff junglemaster boots in reduction with completely free shipping. in spite of the fact that we don’t have belstaff pants on our store, belstaff jackets also go with belstaff boots well.Made using the finest leather, these knee increased Belstaff Boots have undergone a precise ageing process which give them a timeless charm. Belstaff Boots are very rugged, sturdy, cool and very stylish.
belstaff Boots purchase for a lot of women on Belstaff UK Outlet
store online. it is possible to buy belstaff Trailmaster boots, belstaff junglemaster boots in reduction with completely free shipping. in spite of the fact that we don’t have belstaff pants on our store, belstaff jackets also go with belstaff boots well.Made using the finest leather, these knee increased Belstaff Boots have undergone a precise ageing process which give them a timeless charm. Belstaff Boots are very rugged, sturdy, cool and very stylish.
belstaff Boots purchase for a lot of women on Belstaff UK Outlet
store online. it is possible to buy belstaff Trailmaster boots, belstaff junglemaster boots in reduction with completely free shipping. in spite of the fact that we don’t have belstaff pants on our store, belstaff jackets also go with belstaff boots well.Made using the finest leather, these knee increased Belstaff Boots have undergone a precise ageing process which give them a timeless charm. Belstaff Boots are very rugged, sturdy, cool and very stylish.
belstaff Boots purchase for a lot of women on Belstaff UK Outlet
store online. it is possible to buy belstaff Trailmaster boots, belstaff junglemaster boots in reduction with completely free shipping. in spite of the fact that we don’t have belstaff pants on our store, belstaff jackets also go with belstaff boots well.Made using the finest leather, these knee increased Belstaff Boots have undergone a precise ageing process which give them a timeless charm. Belstaff Boots are very rugged, sturdy, cool and very stylish.
belstaff Boots purchase for a lot of women on Belstaff UK Outlet
store online. it is possible to buy belstaff Trailmaster boots, belstaff junglemaster boots in reduction with completely free shipping. in spite of the fact that we don’t have belstaff pants on our store, belstaff jackets also go with belstaff boots well.Made using the finest leather, these knee increased Belstaff Boots have undergone a precise ageing process which give them a timeless charm. Belstaff Boots are very rugged, sturdy, cool and very stylish.
belstaff Boots purchase for a lot of women on Belstaff UK Outlet
store online. it is possible to buy belstaff Trailmaster boots, belstaff junglemaster boots in reduction with completely free shipping. in spite of the fact that we don’t have belstaff pants on our store, belstaff jackets also go with belstaff boots well.Made using the finest leather, these knee increased Belstaff Boots have undergone a precise ageing process which give them a timeless charm. Belstaff Boots are very rugged, sturdy, cool and very stylish.
belstaff Boots purchase for a lot of women on Belstaff UK Outlet
store online. it is possible to buy belstaff Trailmaster boots, belstaff junglemaster boots in reduction with completely free shipping. in spite of the fact that we don’t have belstaff pants on our store, belstaff jackets also go with belstaff boots well.Made using the finest leather, these knee increased Belstaff Boots have undergone a precise ageing process which give them a timeless charm. Belstaff Boots are very rugged, sturdy, cool and very stylish.
belstaff Boots purchase for a lot of women on Belstaff UK Outlet
store online. it is possible to buy belstaff Trailmaster boots, belstaff junglemaster boots in reduction with completely free shipping. in spite of the fact that we don’t have belstaff pants on our store, belstaff jackets also go with belstaff boots well.Made using the finest leather, these knee increased Belstaff Boots have undergone a precise ageing process which give them a timeless charm. Belstaff Boots are very rugged, sturdy, cool and very stylish.
belstaff Boots purchase for a lot of women on Belstaff UK Outlet
store online. it is possible to buy belstaff Trailmaster boots, belstaff junglemaster boots in reduction with completely free shipping. in spite of the fact that we don’t have belstaff pants on our store, belstaff jackets also go with belstaff boots well.Made using the finest leather, these knee increased Belstaff Boots have undergone a precise ageing process which give them a timeless charm. Belstaff Boots are very rugged, sturdy, cool and very stylish.
belstaff Boots purchase for a lot of women on Belstaff UK Outlet
store online. it is possible to buy belstaff Trailmaster boots, belstaff junglemaster boots in reduction with completely free shipping. in spite of the fact that we don’t have belstaff pants on our store, belstaff jackets also go with belstaff boots well.Made using the finest leather, these knee increased Belstaff Boots have undergone a precise ageing process which give them a timeless charm. Belstaff Boots are very rugged, sturdy, cool and very stylish.
belstaff Boots purchase for a lot of women on Belstaff UK Outlet
store online. it is possible to buy belstaff Trailmaster boots, belstaff junglemaster boots in reduction with completely free shipping. in spite of the fact that we don’t have belstaff pants on our store, belstaff jackets also go with belstaff boots well.Made using the finest leather, these knee increased Belstaff Boots have undergone a precise ageing process which give them a timeless charm.
In order to meet all demands, producing belstaff jackets
never reduce. So many brands in the world conluding North Face jackets, Mens Belstaff Jackets
, columbia jackets and also spyder belstaff jacket
, each of them is high quality, workmanship, stylish and comfortable, add waterproof and durable freature, they also support for extreme sports.
That’s good, I was just passing by and got it wonderful to read. Thank you. wound dressings, tegaderm
Belstaff Sale Trialmaster sequence is one of probably the most well liked coats
Thanks.
internette görüntülü olarak okey oyunu oyna, gerçek kisilerle tanis, turnuva heyecanini yasa.
Your site gives me much interesting stuff here, I really enjoyed. I will be back for more new updates here.
Amazing , we all love it
Thank you for your informative post
Your post is informative I really love it Thank you :-)
Your article is so useful and informative Thank you :-)
Your article is so useful and informative Thank you :-)
I really love posting article here in website Thank you :-)
I agree with your description but there are some points need to be clarify. May I ask here. I need some more details. Easy Help
I agree with information you have provided but there are some points need to be clear. Can I ask here. I need some more details.
Blog posts about wedding and bridal are always rare to find , at least with great quality,you qualify for a great blog post writer title,kep the great job happening
are always rare to find , at least with great quality,you qualify for a great blog post writer title,kep the great job happeninghigh quality headphones new design headphones
It is not hard to understand why the question of value is still raised when you consider that today?s outsourcing models have some inherent limitations that reduce the overall gains companies can achieve .
This is really enjoyed Medical Coder Job Description for visiting the nice info in this blog and great technology in this blog Probation Officer Job Description and I had really like it very much for providing the great technology in this blog. This website is really admired for this info in this blog. I am very much satisfied by the info in this blog Personal Trainer Job Description Thank you very much for providing the great technology in this blog. I was really like it Home Health aide Job Description
Forgive and forget Fortune favours the brave From the sublime to the ridiculous is only one step
Slewing bearing called slewing ring bearings, is a comprehensive load to bear a large bearing, can bear large axial, radial load and overturning moment. http://www.1stbearing.com
The professional design make you foot more comfortable. Even more tantalizing,this pattern make your legs look as long as you can,it will make you looked more attractive.Moveover,it has reasonable price.If you are a popular woman,do not miss it.
Technical details of Christian Louboutin Velours Scrunch Suede Boots Coffee:
Fashion, delicate, luxurious Christian louboutins shoes on sale, one of its series is Christian Louboutin Tall Boots, is urbanism collocation. This Christian louboutins shoes design makes people new and refreshing. Red soles shoes is personality, your charm will be wonderful performance.
It is true that you can’t make sure when the iPhone crashed. it is better to make a copy of the files on it.
This code yields the computation that we want and the neat thing is, we are really only computing the piece we specified with window. We’ve essentially formed a general computation and imposed the edges later.
This article is GREAT it can be EXCELLENT JOB and what a great tool!
This is just great to read I have got. Thank you for this wonderful sharing.
the brave From the sublime to the ridiculous is only one step
Thanks for the information, I’ll visit the site again to get update information online shopping
Imposing the Edges Later 72 good post32
Imposing the Edges Later 73 hoo,good article!!I like the post!162
http://www.outfitscosplay.com/cosplay-catalog/dragon-ball-cosplay Deluxe Dragon Ball Cosplay Costumes for Sale.Find your favorite characters and cosplay outfits from all the popular anime and games.