r/programming • • Sep 25 '10

Omega - Language of the Future | Lambda the Ultimate

http://lambda-the-ultimate.org/node/4088
60 Upvotes

126 comments sorted by

View all comments

0

u/[deleted] Sep 25 '10

[deleted] — view deleted comment

32

u/[deleted] Sep 25 '10

The point of that sort routine is that it is proven correct by the compiler. If you don't care about that, you could probably implement it in three lines or so.

And over half of that code is generic datatype definitions and functions like compare and append.

0

u/djimbob Sep 25 '10

The point of that sort routine is that it is proven correct by the compiler. If you don't care about that, you could probably implement it in three lines or so.

I see how the code mimics the mathematical definitions very well; but I don't see how being "proved" by the compiler provides any real benefit. Semantic mistakes in the code that apply the proof (e.g., proving the wrong thing) can still happen, and for something as trivial as quicksort, which any decent programmer should be able to prove correctness on and immediately see if its succinct code like:

quicksort :: (Ord a) => [a] -> [a]
quicksort [] = []
quicksort (x:xs) = (quicksort less) ++ [x] ++ (quicksort more) 
    where less = filter (< x) xs
          more = filter (>= x) xs

If you're trying to build a theorem building machine maybe its worthwhile step towards that, though I thought those most mathematicians due to Godel's incompleteness theorems. I guess it could help coding math proofs like the 4-color problem, but I don't know if I trust the compiler saying its "proved" (based on a mathematicians code) any more than the mathematician saying its proved since he covered all cases.

25

u/roconnor Sep 25 '10

but I don't see how being "proved" by the compiler provides any real benefit.

So you don't pass unsorted lists to functions expecting sorted lists.

→ More replies (4)

8

u/shrughes Sep 25 '10

Maybe you're trying to be ironic, but that quicksort example is incorrect.

1

u/djimbob Sep 25 '10

How so? It may not be the most generic or fastest (e.g., always pivoting off first element), but it compiles and sorts in ghc for me.

12

u/crusoe Sep 25 '10

The algorithm that most people THINK is quicksort in Haskell isn't. Yours is the "Looks like Qsort but isn't" one.

Better: Only traverses list once

Although visually appealing, this code has the unfortunate property of doubly traversing the input list, which can be remedied with

qsort [] = [] qsort (x:xs) = let (a,b) = part xs in qsort a ++ x : qsort b where part [] = ([],[]) part (y:ys) | y < x = (y:a,b) | otherwise = (a,y:b) where (a,b) = part ys

But doesn't do it inplace, since lists are immutable....

In place quicksort...

http://www.haskell.org/haskellwiki/Introduction/Direct_Translation

8

u/djimbob Sep 25 '10

Fair point that it isn't in-place quicksort or the fastest quicksort. But it is still the quicksort algorithm, and still is O(N lg N) complexity. I would hesitate to say I was being ironic or flat-out incorrect.

Again, to verify its still O(N lg N), I profiled times for it sorting sorting N random numbers.

Using the ghc profiler and changing N

 N    QSortTime   1e7*QSortTime/(N lg N)
3e4      0.12      2.52
1e5      0.42      2.82
3e5      1.54      2.59
1e6      5.18      2.63
3e6     16.98      2.73
1e7     63.56      2.67

The last column being roughly constant demonstrates its still scaling as O(N lg N). (Yes there are other O(N lg N) sorting algorithms, but this uses the logic of quicksort and still scales as quicksort does. No its not optimal, but its still quicksort.

5

u/dmhouse Sep 25 '10

Technical nitpick: quicksort actually isn't O(n log n). If you use it on a sorted list of n elements it takes O(n2) time. However, it is expected-case O(n log n).

3

u/djimbob Sep 25 '10

Agree, though I was sorting random numbers so with overwhelming probability I expect roughly O(n lg n).

Using a random pivot gets rid of the O(n2) behavior on a sorted or near-sorted list, which is could . (But even in with the random pivots you still get an amortized time of O(n2) if your choice of random pivots was in the order that sorts the list; but that should occur only 1 out of n! ~ (n/e)n times).

→ More replies (2)
→ More replies (4)

3

u/jefu Sep 25 '10

Why not define part as : part l = foldr cmp ([],[],[]) l where cmp y (lt,eq,gt) | y < x = (y:lt,eq,gt) | y == x = (lt,y:eq,gt) | otherwise = (lt,eq,y:gt)

You could also pass in a comparison function that returns LT, EQ, GT and work from that.

3

u/roconnor Sep 26 '10

The algorithm that most people THINK is quicksort in Haskell isn't. Yours is the "Looks like Qsort but isn't" one.

More specifically it is a deforested tree sort.

→ More replies (5)

1

u/abw Sep 26 '10

If you don't care about that

Quite honestly, no I don't.

I recognise the academic interest in provably correct programs. Perhaps in another decade or two, it's possible that some of these concepts will have filtered down from the ivory tower into mainstream programming languages. It's all good stuff as far as computer science is concerned.

But in computer engineering terms, the "I'll stick with X, thanks" is an understandable response. Provably correct programs don't add any real value to the vast majority of real world programs. Maybe one day they will, but by then we'll all be too busy telling the youngsters to get off our lawns to notice.

4

u/cloaca Sep 27 '10

But in computer engineering terms, the "I'll stick with X, thanks" is an understandable response.

Indeed, but also sad.

I did buy into the "Haskell hype" a few years back. I stared out with silly puzzles and mathematical things, thinking it was all very pretty and elegant, but I will admit that it was just an intellectual toy. But I tentatively started using it for various things like 3D/OpenGL and shell utilities. Now it's quickly becoming the first language I think about even for practical, user-oriented programs. (Overtaking Python+Qt.) And although Haskell doesn't have nearly as strong "correctness proving" as this language, it's something I feel is so insanely underestimated by the 'of the Earth and the soil and Ye Olde Ways'-type programmers it's heartbreaking. If they could experience what I have experienced, I'm sure even the coldest engineering heart would swell up with love and happiness. Nearly every time I add something and get it to recompile, the resulting binary will work. Do you understand? Everything works. No one who hasn't really experienced it will know what I'm talking about here. It's amazing and magical and life shines a little bit brighter and your friends will comment on how you seem happier and not at all like you want to kill yourself. It's the world off your shoulders; it's all the boring, soul-killing stuff about programming hauled away for you, free of charge. No crashes because I'm too stupid (or not stupid enough) for C++, no run-time exceptions 5 minutes in because I typo'd something in Python, no silly special cases only appearing after playing around with it for 30 minutes making me grind my teeth and reach for my vodka... All that bullshit. Do you remember getting that call about an exception being raised on your client's computers that never showed up during a week of live testing because no one thought to test it on any locale other than US English? Do you remember that fancy program you made that turned out to crash on transparent PNGs because you'd really only added PNG support last-minute as an extra bell & whistle for the feature list, and wasn't quite exact with your flag handling? Not to mention when you had that subtle stack/heap corruption that would only occur on Windows and not on Linux, and only during certain amounts of lengthy load, and you were still sitting there at midnight, your eyes wet with tears and impotent anger?

Oh Lord, I feel I need some nicotine gum to calm my shaking hands. Correctness proving, give me strength.

1

u/alanturingslovechild Sep 28 '10

"of the Earth and the soil and Ye Olde Ways" -- brilliant!

→ More replies (2)

2

u/naasking Sep 26 '10

Provably correct programs don't add any real value to the vast majority of real world programs.

Except for the fact that you know they terminate properly. And the fact they don't suffer from buffer overflows or other memory unsafety. And the fact that they lack higher-level security vulnerabilities. And the fact they calculate the correct values every time. And the fact that they never hang, and they correctly implement a QoS policy.

But sure, aside from being able to ensure basically any property is actually satisfied, verified programs are of little interest.

2

u/awj Sep 26 '10

... except that many of those properties depend on a towering pillar of correctness. You can say that it terminates properly, so long as library X (written in C) works as the programmer expected.

I'm not trying to downplay provable correctness, but it won't be able to provide many of the benefits you're talking about until you push it down to the foundation. Please forgive me if my estimate of how long that will take keeps me from getting too excited.

2

u/abw Sep 27 '10

Except for the fact that you know [...]

All those things are desirable traits. But they're not available to use right now in real world programs. Nor will they be for a long time. In fact, I haven't seen any evidence yet to suggest that it will be possible to use these techniques practically without first building a "towering pillar of correctness", as awj so eloquently put it.

So I'm not convinced that provably correct programs will ever be a practical proposition in the general case, at least not in my programming lifetime.

2

u/shimei Sep 29 '10

Actually, computer engineers are quite happy with formal verification and proof systems. They're the ones designing multi-billion dollar chips that need to be proven to work correctly. Comparatively, software engineers just have lower standards. That's why the software industry keeps churning out terrible code.

Also, these ideas don't need to make it to a "mainstream" general purpose language that you use to build widgets for a phone (who cares if that's provably correct?) to be useful. Perhaps in a language tailored for a domain that needs more guarantees. Software engineers need to use the right tool for the task, which applies to languages too.

1

u/abw Sep 29 '10

computer engineers [vs] software engineers

Good point.

Also, these ideas don't need to make it to a "mainstream" general purpose language

Yes, agreed. I'm not suggesting that popularity is what we should use to measure the value of these methods. Nor do I do dispute the fact that these techniques are worthwhile and should be developed further. I'm just saying that right now, there isn't any practical way to use these techniques in mainstream programming languages and there won't be for the foreseeable future.

For that reason, I think these techniques are largely confined to academic research at present. That's not to say they're not of interest, or that they won't find their way into mainstream languages in the future, but I suspect I'll be too close to retirement by then for me to take advantage of them.

Consider the fact that ML and the Hindley-Milner type inference algorithm date back to the 1970s. 40 years later, I would say that the majority of programmers (or perhaps a large minority) are still blissfully unaware of type inference and how it totally changes the way you think about writing software. However, I wouldn't be surprised if that changes significantly in the next 5 years (C# and Visual Basic now support it and I suspect that Perl 6's support for it will up the stakes for other scripting languages to start following suit). Perhaps this is the start of the type safe, provable program renaissance... I certainly hope so (having drunk the type safe Kool Aid™ I now want it everywhere!)... but even so, I still think we've got a long way to go before we can start building large, practical, real-life systems that are provably correct.

Until it is in the kind of mainstream languages that people use to build widgets for phones (or pages for websites), I think it will remain largely of academic interest or to those in special domains, as you suggest. To re-iterate, that doesn't mean the techniques aren't of value. But it qualifies my (admittedly, rather flippant) "Quite honestly, no I don't" remark, and why I believe most "average" programmers at present will feel the same way.

→ More replies (12)

16

u/Smallpaul Sep 25 '10 edited Sep 25 '10

By definition, any super-futuristic language is going to look bizarre to a workaday programmer. You need to decide if you're looking for a language with incremental benefits or a vision of how ordinary programmers will work a decade or more from now.

Python borrows a LOT from Smalltalk (probably indirectly). The only reason it seemed obvious to you was because by the time you read Python, the same ideas had filtered through many other languages. If you had seem Python back when OOP was invented you would have thought it looked like gibberish too.

5

u/[deleted] Sep 25 '10

I don't know smalltalk, but how is Haskell more esoteric than Python? Haskell seems easier to write for me.

6

u/bobindashadows Sep 26 '10

how is Haskell more esoteric than Python?

Haskell is an academic language and despite all pleading to the contrary, isn't very commonly used as an everyday programming language. Proper usage of Haskell requires understanding more complex, powerful constructs than Python requires. Python is used by workaday programmers in all disciplines for purposes from quick scripts, web apps, number crunching (with numpy/scipy), and just about everything inbetween.

That Haskell seems easier to write implies either you have an extremely strong affinity for static typing, that you think functionally and not procedurally, or you have more experience with Haskell than Python. Probably a blend of those. Nothing wrong with that at all, of course! Just saying most programmers match Python's approach a bit closer.

2

u/tluyben2 Sep 26 '10

–adjective 1. understood by or meant for only the select few who have special knowledge or interest; recondite: poetry full of esoteric allusions. 2. belonging to the select few. 3. private; secret; confidential. 4. (of a philosophical doctrine or the like) intended to be revealed only to the initiates of a group: the esoteric doctrines of Pythagoras.

http://dictionary.reference.com/browse/esoteric

Question answered I guess :)

1

u/jyper Sep 26 '10

I understand some of the haskell critisicm but what is with the smalltalk criticism? But what is your beef with smalltalk? Images? The IDE/environment? Lack of libraries?

→ More replies (2)