Domain: haskell.org
Stories and comments across the archive that link to haskell.org.
Comments · 393
-
Monad the name?
Okay, so it's called Monad -- I've only heard this name in one other context, and that's Haskell (http://www.haskell.org./ The interesting thing is that Simon Peyton Jones went to MSR a few years ago.
So, it seems that, either the name is unrealated, and that would suck. Or, that somehow, this is related. *IF* it is realated, I'm not sure how adoption will go. Functional Programming can be a little odd.
Anyone know? -
Re:WowYou are getting "procedural" programming confused with "functional" programming. Functional languages generally refer to languages that concentrate on the evaluation of expressions with no side-effects rather than statements that modify data. Examples of functional languages are:
Note that C and Pascal are decidedly not examples of programming languages designed for functional programming. Wikipedia's page is a decent starting point for learning about this.
http://en.wikipedia.org/wiki/Functional_programmin g/ -
Functional Compilers, anyone?
Good thinking, IBM. Now, let's get SML/NJ, Haskell, and O'Caml ported to these things.
"Why", you may wonder, but the answer is simple: Referential transparency or any kind of confinement of side-effects makes for easy parallelisation, which is what these Cell thingies are supposed to rock at.
This might be the one thing that will put FP back into the undergraduate curriculum.
-- Christoph -
Python?.. a set of riddles that require a little bit of Python programming to be solved.
Cross out the "Python" above. There is no need to use Python to solve these puzzles. I use Haskell. Some other language might work for someone else. There is nothing Python specific about the challenges. But they are indeed quite amusing.
-
Teaching vs. Industrial UseHell yeah. I learned the same languages in that order when I was in grade school and high school.
BASIC: self-taught including line numbers and even *shudder* edlin once one a random computer in elementary school, plus a year of high school. A wonderful language to learn with.
Pascal: a dead language. Why the hell are people still using it? Whatever, I learned it in two years of high school, learned about pointers and trees and ADTs. Since it was DESIGNED as an educational language, NOT as an industrial language, it was great to learn with.
C/C++: should die, except for programming kernels and hardware libraries. But I learned some of it in the last year of high school, and more in college. Great language for low-level manipulation and byte-counting accuracy (that's C only, not C++).
They're trying to teach my brother basic computer science at UT Dallas by using Java. And not just Java, but Swing. It is a wondefully powerful language, just like C, and it has native threading, exceptions, and class extensions, so it blows C++ out of the water. But it is a horrible language with which to teach computer science. Horrible, horrible, horrible, even more so than C. My brother didn't know what a 'class' was, and they wanted him to use Java! Give me a break, and him, too.
Once I got to college, I learned Haskell, then Python, PHP, a little JAVA, LISP, and assembly (okay, assembly for a simple machine). Haskell kicked my ass. Want to know why? Because I already 'knew' how to program. What I 'knew' was the suspension of disbelief required for working in the imperative programming world. Haskell is a great language for teaching people who do NOT know programming at all. My suggestion: start with Haskell, then move to Python (which is like BASIC in that it is interpreted and has a sparse syntax).
Why do we have to make it hard on people during education? We should use Haskell, Python, Pascal, or BASIC in order to teach them. And why do we have to make it hard on ourselves as programmers? We should not use Pascal or BASIC for anything, and we should use other languages for what they are good for.
And what is C good for? Explicit control and direction. Pascal? Nothing in the industry. If you're going non-standard (i.e. not C/C++), and you need absolutely enforced types, then byte the bullet and learn Haskell. Here, I'll make it easy for you: I've actually written a tutorial about Haskell for people who know languages like C (including Pascal, Perl, Python, PHP, etc.). If you know any of those languages, and you want to learn a better, simpler, more free way , please check it out. I made it just for you, really! Oh, just so I mention it, it's fairly easy to call external code from Haskell, so you can still be naughty if you need to.
Thanks for the walk down memory lane.
-
Haskell & DSLs [was: Are you trying to be obtu
Since when can you write a domain specific language/interpreter in just about a day or two???
Heck, the Haskell people love to do just that type of thing. Here's an online bibliography on Embedding Domain-Specific Languages in Haskell to get you started. In fact, in the intro to Haskell book, The Haskell School of Expression: you construct a number of DSLs.This book teaches functional programming as a way of thinking and problem solving, using Haskell, the most popular purely functional language. Rather than using the conventional mathematical examples commonly found in other programming language textbooks, the author draws examples from multimedia applications, including graphics, animation, and computer music, thus rewarding the reader with working programs for inherently more interesting applications. Aimed at both beginning and advanced programmers, this tutorial begins with a gentle introduction to functional programming and moves rapidly on to more advanced topics. An underlying theme is the design and implementation of domain specific languages, using three examples: FAL (a Functional Animation Language), IRL (an Imperative Robot Language), and MDL (a Music Description Language)...
And it seems like there's quite a few people doing DSLs in languages other than lisp. -
Haskell & DSLs [was: Are you trying to be obtu
Since when can you write a domain specific language/interpreter in just about a day or two???
Heck, the Haskell people love to do just that type of thing. Here's an online bibliography on Embedding Domain-Specific Languages in Haskell to get you started. In fact, in the intro to Haskell book, The Haskell School of Expression: you construct a number of DSLs.This book teaches functional programming as a way of thinking and problem solving, using Haskell, the most popular purely functional language. Rather than using the conventional mathematical examples commonly found in other programming language textbooks, the author draws examples from multimedia applications, including graphics, animation, and computer music, thus rewarding the reader with working programs for inherently more interesting applications. Aimed at both beginning and advanced programmers, this tutorial begins with a gentle introduction to functional programming and moves rapidly on to more advanced topics. An underlying theme is the design and implementation of domain specific languages, using three examples: FAL (a Functional Animation Language), IRL (an Imperative Robot Language), and MDL (a Music Description Language)...
And it seems like there's quite a few people doing DSLs in languages other than lisp. -
C is NOT functional
Admittedly, I'm an EE and not a Software person, but I've been working a lot with FPGA design and this involves the use of a few "functional" programming languages such as the Scheme-like confluence Hardware Description Language (HDL).
ANSI and ISO C are imperative, sequential, PROCEDURAL languages.
From my (possibly wrong) understanding, languages such as Haskell (Wikipedia) and Scheme (Wikipedia) are "functional".
These are so far from anything at all like C programming, Haskell in particular for some reason reminds me of that movie Event Horizon, but that's probably just my warped mind thinking irrelevant thoughts again...
I'm told that the Haskell course taught at my University is a source of great frustration to many programmer wannabes who can never get their head around the "functional" programming paradigm and are forever stuck in their Java ways.
So, if C is classed as "functional" in your books, what would Haskell be? -
Re:This is not a troll, but a query...
Really? Which functional language has macros?
Maybe you should look at Template Haskell...Template Haskell is an extension to Haskell 98 that allows you to do type-safe compile-time meta-programming, with Haskell both as the manipulating language and the language being manipulated.
Intuitively Template Haskell provides new language features that allow us to convert back and forth between concrete syntax, i.e. what you would type when you write normal Haskell code, and abstract syntax trees. These abstract syntax trees are represented using Haskell datatypes and, at compile time, they can be manipulated by Haskell code. This allows you to reify (convert from concrete syntax to an abstract syntax tree) some code, transform it and splice it back in (convert back again), or even to produce completely new code and splice that in, while the compiler is compiling your module.
...Which functional language lets you redefine stuff in a running image?
Erlang allows you change stuff in running code...12.3 Code Replacement
Erlang supports change of code in a running system. Code replacement is done on module level.
The code of a module can exist in two variants in a system: current and old. When a module is loaded into the system for the first time, the code becomes 'current'. If then a new instance of the module is loaded, the code of the previous instance becomes 'old' and the new instance becomes 'current'.
Both old and current code is valid, and may be evaluated concurrently. Fully qualified function calls always refer to current code. Old code may still be evaluated because of processes lingering in the old code...
-
The advantages of functional languages
- C++ is more readable than assembler
- C# and Java are more readable than C++ ...
- At the end of this list are functional programming languages.
If you can read source more easily, then maintainability will be better. Most projects maintain code, they write new code less often.
This article will tell you why you should be interested in functional programming languages (this link is about Lisp). If you're smart and open minded, you will be convinced.
The best functional languages are Haskell and Erlang (click "next" at the bottom of the page). But like the review and link indicate, there's actual value to learning Lisp.
However, the book review is much too in-depth and has jargon.
A simpler example: with Java you prevent bugs by static typing variables, example:
int numberOfTries = 3;
If you later try to fill "numberOfTries" with a string, the compiler will warn you of a bug and you'll have prevented it. The Java compiler makes it a rule that you have to give a type to your variable so your code quality will be higher (fewer bugs).
With Haskell, you don't have to type int. Haskell will figure out the type for you, you get the benefit of preventing bugs with the convenience of not having to type variables. There are other good features like that in functional programming languages.
You could say that every language puts restrictions on what the programmer can do. I mean writing the source code is bottlenecked by the rules of the language (every variable should have a type. You can't do this/that etc.) so that the resulting code AUTOMATICALLY has fewer bugs. Well the amount of source "laws" in functional languages is much lower than in C++ and Java. This means that there is less to remember for a programmer and there is less chance for rules to conflict/interact with each other (in Java you can't use certain variable types in static classes = another meta rule to remember).
Besides having less rules to remember and take into consideration. The functional languages have also chosen the best "laws" to follow. I mean that if you follow the source laws of Java, it's still relatively easy to produce buggy programs, with functional languages it's harder to produce implementation bugs (thinking bugs are always possible but that's your problem).
The only problems with functional programming languages is that the rules which govern source code are very good, but also very different from the rules in traditional programming languages. It might seem like thinking upside down/backwards for people already familiar with procedural languages. Another problem is that because of humans sticking to what they know, the libraries of the functional languages aren't as extensive as those of Java for example. This means that you'll have to program more parts of your program yourself instead of just using a ready made library which fits the task. This problem is limited by the fact that you can program 10 times faster than in Java and, as I said, maintenance takes up most of the time anyway.
The reason I chose Erlang is because with functional purely functional programming languages like Erlang, you can automatically multitask your program over several CPU's (or this will take minimal effort). Nice feature to have in the future because every CPU manufacturer is going multi-core chip now. The future is in multiprocessor machines, not higher clockspeeds (unless diamond wafers become viable) (Lisp is not purely functional by the way).
Also, you can easily make a server that never goes down with Erlang because your server is automatically clustered. Just plonk down a couple networked PC's and if one dies, the server cluster will just keep on going (a bit slower) until you replaced the power supply of the broken PC.
There are tons of other advantages but, as I said, -
Re:Very CuteI didn't understand OOP 3 years ago (my colleagues might say I still don't) and that was after several months worth of experimentation with C++ and Java, and at least five textbooks full of examples very similar to yours.
The AC you were trying to help may well be in the same situation. Maybe even you are. I agree with grandparent that what you are illustrating is ADT's, not OO. I think part of the reason it took me so long to get the hang of OOP is that I made the same mistake, confusing ADT's and OO (the textbooks didn't help there either).
ADT's are not a step towards understanding OOP. At least not for me. What helped me were functional languages such as Haskell, where you can encapsulate behaviour and data within functions which are themselves passed between other functions (really very similar to polymorphism).
Maybe its me who still doesn't understand OO. My favourite OO language is PHP4, but several of my OO fan friends have (for different reasons) said its not "properly OO".
-
Re:Perl doesn't kill readability...
under no circumstances allow yourself to get near functional languages, or you will collapse in sheer incomprehension. There's More Than Perl's Number Of Ways To Do It in those languages.
Huh?
I find functional languages to be much cleaner and more consistently coded in than Perl[1]. Could you provide a couple of examples of this syntax smorgasbord you're talking about?
[1] Of course, there are always examples of arcane and overly complicated ways of doing things, such as this example. But I'm speaking in generalities here... -
The language is very important
- C++ is more readable than assembler
- C# and Java are more readable than C++ ...
- At the end of this list are functional programming languages.
If you can read source more easily, then maintainability will be better.
This article will tell you why you should be interested in functional programming languages. If you're smart and open minded, you will be convinced.
The best functional languages are Haskell and Erlang (click "next" at the bottom of the page).
For example, with Java you prevent bugs by static typing variables, example:
int numberOfTries = 3;
If you later try to fill "numberOfTries" with a string, the compiler will warn you of a bug and you'll have prevented it.
With Haskell, you don't have to type int. Haskell will figure out the type for you, you get the benefit of preventing bugs with the convenience of not having to type variables.
The reason I chose Erlang is because with functional purely functional programming languages like Erlang, you can automatically multitask your program over several CPU's (or this will take minimal effort). Nice feature to have in the future because every CPU manufacturere is going multi-core chip now. Also, you can easily make a server that never goes down with Erlang because your server is automatically clustered. Just plonk down a couple networked PC's and if one dies, the server cluster will just keep on going (a bit slower) until you replaced the power supply of the broken PC.
There are tons of other advantages but, as I said, the above links will convince you if you're smart. Haskell is a bit more academic in nature, they're figuring out the best possible language and Erlang is more polished and ready to go. It was invented by Ericsson to create ultra reliable realtime servers. -
Re:Slated for release.
Haskell is the best.
-
Re:Comparison of Programming Languages
You might also be interested in Haskell vs. Ada vs. C++ vs. Awk vs.
..., An Experiment in Software Prototyping Productivity -
Haskell is a language for writing languages.This is a standard paradigm in the Haskell world. You write a new language that fits the problem domain. These are called Domain Specific Languages
For example, Simon Peyton-Jones wrote a combinator library to describe financial contracts and used it to describe the collapse of Enron. (With fascinating conclusions!)
Paul Hudak has written Dance and Haskore. Dance is a language that describes dance choreography, with a handy OpenGL viewer. Haskore is a music scoring language where code looks like:> cMajScale = Tempo 2
Languages, spoken or programming, or any other means of expression is most efficient when it fits the problem domain.
> (line [c 4 en [], d 4 en [], e 4 en [], f 4 en [],
> g 4 en [], a 4 en [], b 4 en [], c 5 en []])
If this sort of thing interests you, Lambda The Ultimate is a good forum to learn more. -
Haskell is a language for writing languages.This is a standard paradigm in the Haskell world. You write a new language that fits the problem domain. These are called Domain Specific Languages
For example, Simon Peyton-Jones wrote a combinator library to describe financial contracts and used it to describe the collapse of Enron. (With fascinating conclusions!)
Paul Hudak has written Dance and Haskore. Dance is a language that describes dance choreography, with a handy OpenGL viewer. Haskore is a music scoring language where code looks like:> cMajScale = Tempo 2
Languages, spoken or programming, or any other means of expression is most efficient when it fits the problem domain.
> (line [c 4 en [], d 4 en [], e 4 en [], f 4 en [],
> g 4 en [], a 4 en [], b 4 en [], c 5 en []])
If this sort of thing interests you, Lambda The Ultimate is a good forum to learn more. -
Re:Bullshit they are patenting the hash table...
Umm, there's an entire genre of programming languages where the program is considered a single big expression. It's called functional programming. For example, see http://www.haskell.org/aboutHaskell.html in the "What is functional programming?" section. The fact that an expression might be boolean wouldn't make such a programming language any less expressive since all integer and character operations are ultimately just optimized combinations of bitwise operations. This is particularly true since the purpose of the language in question is to express boolean predicates concerning whether or not a particular system infringes on the patented system's design.
-
HaskellHaskell is also a great language for performing math. It'd be hard to get a nicer notation for the factorial than something like this...
fac n = product [1..n]
-
Re:Willful Ignorance
first class functions in a static language? This is like having mallable steel trusses? What is this trying to do again? If you want first class functions, you'll want a define-on-the-fly language as well.
You, sir, are either trolling or criminally ignorant.
Here is a statically typed, natively compiled language that provides fully first-class functions.
Here is another.
There are many others; those are just the most widely used. -
Re:Intrigued?
OCaml's major problem is that, like every other functional language available today, the breadth of its standard library and third-party libraries is totally pathetic in comparison to the likes of Java and Python. The same limitation applies to Lisp, Scheme, Haskell, Erlang, etc.
I don't know; I've always been able to find libraries that I needed for Haskell; there are quite a few listed on the Haskell libraries page. It seemed to me, when I was evaluating OCaml, that a lack of libraries bindings or bindings to other language's libraries was not a problem. They've got quite a decent database of extensions at The Camel Humps
I'm mainly a Java and Ruby developer, though, so I may not have stressed tested the availability of Haskell libraries. Java doesn't use libraries; if somebody writes a third-party library for it, Sun re-implements it, poorly, and bundles it with the VM, which effectively kills the original, and often superior, library. And Ruby... well, you just create whatever bindings you need, dynamically, with 'dl'.
--- SER
-
Re:Hold Crap!Assembly Language (imperitive style) is the latin of programming. Functional programming is, what, esperanto? Useful in some limited circles, but generally unpopular?
Well, assembly is more like the Latin of the von Neumann architecture (and thus very important to learn), while a functional language like Haskell is more along the lines of the Latin of the mathematics of computation, and thus also important to learn.
Showing off your mastery of OCaml doesn't help anyone understand Haskell better
a) I switched to OCaml, because I am more familiar with it (and able to write proper code off the top of my head in it) and for an example like quicksort, it's very close to Haskell (without the list comprehensions). b) As for showing off my "mastery" of the language, as I pointed out, the definition of rec is in section 1.1 of the OCaml manual. It is the sixth line of OCaml code that someone looking in the manual would see. And if you care, here's quicksort in Haskell (from Haskell.org):
qsort [] = []
And basic programming in an imperative style requires that you document the names of your variables and choose meaningful names
qsort (x:xs) = qsort elts_lt_x ++ [x] ++ qsort elts_greq_x
where
elts_lt_x = [y | y <- xs, y < x]
elts_greq_x = [y | y <- xs, y >= x]Yes. And I suppose I should have used lst or theList for l, head for h, and tail for t. But h, t, and l are so common in ML literature and code (much like i and j as throwaway loop counters, and foo, bar, and baz in pseudocode), that a brief amount of exposure to the language would make them instantly familiar. Besides, my use of less and greater didn't seem to help...
BTW: Imperative programming requires that? Since when? Why is it that Perl has its reputation for looking like line noise? Have you looked at the IOCCC entries lately? Crap variable names and lack of documentation are available in all languages...
In a programming language, "+" could be string concatenation, for example, so that "hello" + 3 yields "hello3".
Yeah, in a language with horrible typing properties, but that's a rant for a different time.
Yes, I'm sure it is, somewhere.
Yeah, right at the spot I linked to. In the OCaml manual, under the section that documents the List module.
Actually, the example I gave was straight from the (minimal) introduction to functional programming I got in school. Which re-enforces my point that functional programming isn't so simple, if I got it wrong.
So you got a minimal (and apparently pretty damn poor) education in recursion and FP, and you're using that experience to damn a whole class of programming languages? Does that really make sense to you?
My point was that recursion is usually more complicated than an imperative alternative.
And my point was that you pulled a contrived example of recursion out of a hat and used it to damn FP. As I said, that's akin to my using Duff's device or this example of printing some strings to damn C. The oddball cases don't tell you anything about the average ones...
Doesn't the recursive version need to put n -1 lists on the stack, (until it unwinds to the empty list), each of size one smaller? I get n-1(n-2)/2 space usage for an operation that should take 2*n space. Am I wrong? Is this a bad example?
Well, depending on how you implement it, yes. As a pure recursive process, it will consume linear space instead of constant space (in terms of stack frames). However, you can use an iterative (tail-recursive) process (with a recursive procedure) to use constant stack space. Ex:
let tr_map f lst =
let rec map_helper f lst acc =
match lst with
[] -> List.rev acc
| head::tail -> map_helper f tail ((f head)::acc) in
map_helper f lst [];; -
Re:Interesting app. non-troll questionsI can't answer all of your questions. The mailing list would be the place to ask.
- 2. Next question, can Haskell be embedded inline in Perl code?
Not that I'm aware. However, all you need is an embeddable Haskell interpreter. I believe this is possible with Hugs, which has a "server interface", and possibly even with ghc (the native compiler that Darcs is compiled with). You'd probably have to write the C/Perl interface yourself.
- 3. Can the quantum theory of patches be implemented as a Perl module
...
Certainly.
- 4. Reading about the symmetry or lack of it, concepts of physics this is helping me think about an app of my own. I'd like to read more about this does anyone have links?
More than anything it's mathematics. But David Roundy, the author of Darcs, is a physicist, and may have some pointers for you.
- 5. Time to learn Haskell!! Great!
If you're a Perl hacker, you might be interested in this. Scary, eh?
-
Re:Interesting app. non-troll questionsI can't answer all of your questions. The mailing list would be the place to ask.
- 2. Next question, can Haskell be embedded inline in Perl code?
Not that I'm aware. However, all you need is an embeddable Haskell interpreter. I believe this is possible with Hugs, which has a "server interface", and possibly even with ghc (the native compiler that Darcs is compiled with). You'd probably have to write the C/Perl interface yourself.
- 3. Can the quantum theory of patches be implemented as a Perl module
...
Certainly.
- 4. Reading about the symmetry or lack of it, concepts of physics this is helping me think about an app of my own. I'd like to read more about this does anyone have links?
More than anything it's mathematics. But David Roundy, the author of Darcs, is a physicist, and may have some pointers for you.
- 5. Time to learn Haskell!! Great!
If you're a Perl hacker, you might be interested in this. Scary, eh?
-
Re:Interesting app. non-troll questionsI can't answer all of your questions. The mailing list would be the place to ask.
- 2. Next question, can Haskell be embedded inline in Perl code?
Not that I'm aware. However, all you need is an embeddable Haskell interpreter. I believe this is possible with Hugs, which has a "server interface", and possibly even with ghc (the native compiler that Darcs is compiled with). You'd probably have to write the C/Perl interface yourself.
- 3. Can the quantum theory of patches be implemented as a Perl module
...
Certainly.
- 4. Reading about the symmetry or lack of it, concepts of physics this is helping me think about an app of my own. I'd like to read more about this does anyone have links?
More than anything it's mathematics. But David Roundy, the author of Darcs, is a physicist, and may have some pointers for you.
- 5. Time to learn Haskell!! Great!
If you're a Perl hacker, you might be interested in this. Scary, eh?
-
Re:I've never quite understood...
What SuperKenall said is correct. However, some languages have more differences than others.
All the .NET languages MS ships are all about the same; the only difference is syntax. .NET requires all compatible languages to adhere to the same capabilities so they can be 100% compatible with each other. Unfortunately, it also requires all the languages it supports to be dumbed down to the lowest common denominator. There is a very long list of things that had to be removed from ISO C++ to create Managed C++, because including them would make it incompatible with VB and C# (and .NET), such as multiple inheritance, templates (non-type params too), pointers, member pointers, etc.
Functionally, VB.NET, C#, J#, and Managed C++ all have exactly the same capibilities. They are all sequential, procedural, imperative, object-oriented languages that support single inheritance, interfaces, events, exceptions, type generics(they will in v2.0), reflection and share a common runtime library and work in a sandboxed VM. The ONLY differences between them are in syntax. So, it doesn't really matter which of these languages are used unless someone in the group doesn't know the syntax for a language in a source file they need to work on. The interfaces between them will be equivalent regardless of language.
Compare this to a functional language such as Common LISP or Scheme, or a declaritive rule-baed language like Prolog or Mercury. Mercury can compile to .NET (it normally compiles to C), but you can forget about a runtime system like Prolog being compatible with .NET. .NET doesn't understand functions that don't have an implementation until you've decided the direction the argumets are flowing (a very big part of declaritive languages), .NET doesn't understand state tracking and backtracking or multiple modes based on detirminism, .NET doesn't understand multiple possible results for a single variable (a list is the closest you can get; it isn't the same because you have to do all the handling yourself which defeats the purpose).
Haskell has to jump through hoops to get the needed multiple inheritance to work.
OTOH, there are some interesting projects like F#, an OCaml like functional language. It has some serious issues to be compatible with .NET, though.
It's like Microsoft offers you several languages, but they are all the same. The illusion of choices without really having any. They should just be like Java and admit that there might as well be one language-- seriously, Java could have all the multi-language support of .NET if there were bytecode compilers for other languages. .NET and Java are so alike in function anyways.
As for what languages should be used when, where and by whom: I don't know. I'm still trying to figure that out. I know that some are good and bad for certain things, but I also know that personal preference is important, too.
</rant> -
Not "Natural Language Programming"Argh! The slashdot title completely mischaracterizes the article. The authors never use the term "natural language" at all! They call what they're talking about "natural programming", and if you read the article I hope you'll agree that it is something we should all be longing for: the ability to express ourselves in code that is close to the problem domain.
IMO, the best direction for natural programming is embedded domain-specific languages. The best direction for natural debugging is a harder problem. It's well known that many expert programmers still find "printf" debugging the best option, which suggests to me that tracing systems are promising. Of course, powerful type systems eliminate many possible run-time bugs, but then you need a type debugger....
-
Re:What do they teach in undergrad now?Some universities teach Haskell - a functional language. It has a cross-platform, open-source interpreter/compiler. Some really cool things can be done in the language, including the 'unlimited' size Integer type, lazy evaluation and higher order functions. Of course, procedural people will probably have some trouble getting used to having no real variables and no loops.
Some sample code to find the maximum Integer in a list of Integers:
max :: [Integer] -> Integer
max (last:[]) = last
max (first:rest)
| first > max(rest) = first
| otherwise = max(rest)
-
Re:What do they teach in undergrad now?Some universities teach Haskell - a functional language. It has a cross-platform, open-source interpreter/compiler. Some really cool things can be done in the language, including the 'unlimited' size Integer type, lazy evaluation and higher order functions. Of course, procedural people will probably have some trouble getting used to having no real variables and no loops.
Some sample code to find the maximum Integer in a list of Integers:
max :: [Integer] -> Integer
max (last:[]) = last
max (first:rest)
| first > max(rest) = first
| otherwise = max(rest)
-
Re:Look, I program in PerlI am a firm believer in using the right tool for the job. I have written a lot of code in Python, such as OfflineIMAP and PyGopherd. I also use OCaml (and have a utility library for it) and Haskell (and have a utility library for it too).
For experienced programmers, learning a new language is not hard, especially if it is similar to what you already know. Python is similar to what you already know.
Any given problem could likely be solved in almost any given modern language. I could write an IMAP client in C, a Web server in Java, or a database client in C++.
In Python, you can write correct solutions to many network-related problems with astonishingly little code. And by correct, I mean with error detection everywhere (and handling where appropriate), safe handling of strings (not an issue in Python usually, but a constant problem in C), no deadlock conditions, etc. And what's more, those solutions are usually readable. There are some examples in the book of that. There's a simple FTP mirroring example in the book. 75 lines of code (excluding blank lines).
Now, I could have written it in C, Perl, Haskell, OCaml, Java, Lisp, Pascal, whatever. That's absolutely true. Most of those would not have let me do it in 75 lines of readable code using solely a component that comes out of the box with the language.
Sometimes, the time it takes you to learn a new language and develop a correct, effective solution in that language is less than the time it takes you to develop an incorrect solution in another. Sometimes not, and it's better to stick to the language you know. My point is that you should not always assume this is best.
How about another example. A little keyboard interaction program. Compare:
Python:
from sys import stdin
print "Who are you?"
name = stdin.readline().strip()
print "I'm glad to meet you, %s." % nameHaskell:
main = interact ((++) "Who are you?\n"
.
(++) "I'm glad to meet you, " .
((++) `flip` ".\n") . head . lines )Java:
import java.io.*;
class Hello {
public static void main (String[] args) throws IOException {
BufferedReader ki = new BufferedReader(new
InputStreamReader(System.in));
System.out.println("Who are you?");
String name = ki.readLine();
System.out.println("I'm glad to meet you, " + name + ".");
}
}Which do you think makes it easiest to interact with the user? I'd have to give the award to Python or Haskell. The Haskell example is a very different one from what you may be used to (hint: ++ is the concatenation operator), as it relies on the lazy and functional nature of the language, but it nonetheless is a concept that scales to incredibly powerful things.
Don't limit yourself by what language you prefer. Prefer a language by what problem you must solve.
(Sorry, it looks like
/. stripped the indentation from these examples) -
functional programming to the rescue
-
distributed systems are more interesting
I like Subversion just fine as a "better CVS" but if you're looking for a better version control system altogether, I would look into distributed version control systems like arch, or if you're looking for something with a better learning curve, darcs is really cool, and is implemented in the glorious Haskell programming language.
Distributed systems like these have a lot of advantages over the CVS/SVN model. -
Make it easier to audit
I'll suggest here that proper tools are an important way to prevent bugs and make auditing (reasoning about) software easier. And C is probably not a proper tool for creating secure software. Oh sure, if you're a super human coder and stick to a rigorously defined coding standard and have a team of other super human coders auditing the code with a fine tooth comb, you can produce C programs with fewer bugs than normal. But why not let the machines do the work for us? Try a language like O'Caml, or Haskell, you might like it! Besides having fewer lines of code to audit, you'll pretty much eliminate buffer overflows, fence post errors, interger overflows, etc.
-
Bah!
Imagine what one could do with a real language... http://haskell.org/libraries/#music
-
Re:Future Open Source efforts?Were there any past ones?
Yes.
Just one example: the Glasgow Haskell Compiler has been developed by people at Microsoft Research for many years now. GHC is released under a BSD_like license.
I worked for MS until fairly recently (which, incidentally, is why I'm posting AC). In my view the single greatest factor which inhibits much more stuff being released Open Source is the MS Legal team. I had a hell of a job being allowed to contribute to a BSD-licensed project.
-
Re:who cares what he says?
And if you really can't tolerate the parentheses, look at Haskell. It's about as easy to learn as Python and more productive (and there are JVM/NET bridges available too).
> not by average programmers
Gosling once noted that Java *was* a blue-collar language designed to get the job done, contrasting with the `purity' of Smalltalk. While I agree, there's a place for Java, I can only hope one day Sun/MS/IBM will see the light and offer a non-procedural language as a first-class offering.
-
Re:Communication error
/= does not mean "not equals" != does.
Here's a nickel. Go buy a real programming language.
-
Re:The correct pricing structure for most software
If all software was free, why would anyone bother developing it?
Gee, I can't think of anyone who would develop software without getting paid for it...
But seriously, there are several reasons people would write software whose price is 0:
- People want better software to do $WHATEVER (for values of $WHATEVER that make money, which is most of them), so they write it
- People want to get a job as a programmer so they write a software package to prove they aren't total code monkeys
- People like fame; they like being admired and appreciated
- An industry consortium decides they need an open, standard, free way to do $WHATEVER
- Some people have a political motivation to undermine proprietary software (we may not have that same motivation; but it is a real driving force for some people)
- Some people like to help others (ditto)
- Your company might want to make your product universally (or nearly so) used in order to be able to charge money for training, certification, etc.
- I mentioned 15 high-profile products that are competitive with best-of-breed and are available for $0 (and not all of it is Free as in speech). All of them were written because one of the above bullet points (or one I forgot) applied.
There are lots of motivations for people's actions besides money.
-
Re:Esoteric LanguagesYah, I'd love to pick up and use O'Caml, but the biggest barrier is interfacing with other libraries.
You might want to give Haskell a try then. It has excellent support for interfacing to foreign languages (at least the GHC compiler), and I prefer it over OCaml for its clean design.
Sebastian
-
Re:Lisp
If you like LISP, try looking at ML or Haskell. In my mind, better finctional languages than LISP. They don't have dynamic typing (both very strictly statically typed), but they have generics which are almost as useful. Plus, they are a joy to code in. I wrote a raytracer in Haskell last year. Lots of fun it was.
-
Re:From an ocaml convert:I suggest you also take a look at Haskell, if you have not done so already. Haskell completely does away with side effects, performing IO operations in a controlled manner through the use of a mathematical concept known as monads. It also adds lazy evaluation. This has some nice capabilities, such as being able to express concepts as infinite lists, which are then only evaluated as far as necessary.
I have used OCaml a bit, and one of the things that most irritated me about it was its complete lack of operator overloading; having to use "+" for integer addition, and ".+" for floating point addition, just seems so wrong to me. Haskell uses type classes to allow ad-hoc polymorphism in a controlled manner.
One advantage that OCaml has over Haskell is speed; current Haskell implementations produce code somewhere between imperitive compiled languages and interpreted languages. However, there is another language, called Clean, that is nearly identical to Haskell in many ways, but claims to have speed comparable to C.
Back to the topic of the discussion, Haskell is probably not the best choice for quick and dirty one time scripting uses. The use of monads for doing IO adds a constant cost that is burdensome for very small programs, and gets payed back only with larger programs where the controlled approach to IO increases robustness.
-
Re:I like Gentoo...The point here is that every admin has an off day; a good tool warns you before you do something silly, then lets you do it anyway. Debian's apt and dpkg are a good tool in this field; both warn me if I'm about to remove something I shouldn't, let me know what I'll break by removing them, and allow me to do it anyway if I really want to.
A bad tool like emerge lets you do something very stupid without trying to warn you; this is not to say that the admin who types "emerge unmerge gcc" is not at fault, rather that if emerge were even better, it would warn the admin that they're about to have trouble. After all, said admin might be intending to remove ghc, having lost interest in Haskell
Plus, I want to introduce new people to Linux who aren't computer types; that way, if they end up in management, they're more likely to accept that Linux can be good enough. This involves setting up their computer, having ssh access in case it breaks, and introducing them to admin tools bit by bit. I would be happier if I could trust emerge to warn people when they do something stupid.
-
Re:Windows and Linux examples, yes
Java, among other high level languages (lisp/scheme, Objective CAML, Standard ML, Haskell, etc), are memory safe because they hide the issue of memory management under the carpet by using a garbage collector. Since the language itself does not have the expressive power to deal with memory directly (some has strong type checking that guarantees even stronger memory safety properties), they're considered "safe." However, a clever hacker might handcraft in bytecode, thus bypassing the type system entirely. The runtime system of the language (which you may consider as the operating system in a board sense) still needs to perform dynamic security policy checking.
On the other hand, the critism on Java or any other high level languages as an interpreted language is ill-founded, as those languages can be compiled to run as native executable.
-
OT: HaskellWell, if you want a innovative language (rather than a pragmatic one), Haskell should definitely not be left out. Granted, it may be a little hard to use if you just want to write real-life programs (quite a lot of computer-science stuff are involved just for mutable state), but its interestingness beats OCAML and even Lisp if you are getting tired of 20 slightly different imperative languages. The language is also well supported in the free software community.
Of course, I'm not disparaging Larry's work here. Perl is a good and pragmatic language, and I'm glad to find it getting rid of the historical ugly parts..
-
five words
Haskell
Haskell
Haskell
Haskell
and of course, let's not forget about ! -
Re:Here we go....
Written like someone who has never used a functional language before. And I know a lot of functional programmers that would argue that OOP is not the way.
Give Haskell or Erlang a try. If you've never done functional programming it'll take a while to get used to it but it's worth it. I wouldn't bother with O'Caml straight away because it's kinda convoluted and the default syntax sucks.
Personally I feel future better languages will combine OOP and functional programming. Some languages are already doing it but I haven't seen any really tasty combinations yet. -
Oh, come on, stick your head outside the box
The fact is that regardless of what methodologys used when developing software, in the end you are simply giving instructions to the computer what to do.
Blah. In imperative languages, you do.
In pure functional languages like Haskell, you don't.
And I really don't know why neural networks aren't used en masse to train computers.
-
Re:A challenge for Haskell hackersYou're kidding, right? It depends, of course, on your representation of a permutation; let's take [(Int, Int)] as our permutation type. So the permutation on three elements that reverses it is [(1,3),(2,2),(3,1)].
invert
Now, if you want to use [Int] as a representation, so that the example permutation is [3,2,1], then you need to first add the indices (linear time), reducing it to the previous problem, and then extract the corresponding list. Therein lies the rub. :: [(Int,Int)] -> [(Int,Int)]
invert = map (\(a,b) -> (b,a))It's not the imperative nature of the permutation algorithm that's magic; it's that C provides a primitive for (it seems) constant-time array access. Provide such a primitive in Haskell (see the Array class) and you have essentially the same linear-time algorithm. In fact, the Array section of the Haskell 98 report provides the following example:
-- Inverting an array that holds a permutation of its indices
invPerm :: (Ix a) => Array a a -> Array a a
invPerm a = array b [(a!i, i) | i <- range b]
where b = bounds a -
Re:Graphical Programming and LearningFunny you should mention pong.
This book contains paddleball in something like 20 lines of code. The book's website provides the code in an archive, in the file Fal.lhs. It is mixed in with the rest of the code for the functional animation module; the version presented in the book itself shows just the paddleball portion. I found it very interesting that programs with this degree of complexity could be implemented with so little code.
-
It Works Like This:
Short answer: IO is an exit value, just like you said.
Long answer:
Monads are a pattern for hiding a state that gets passed from a sequence of functions. For example, when you assign to a variable in an imperative language, the value of that variable in the implicit state is updated and all future phrases accessing that variable will get the new value. If you're using a Haskell state monad it works the same way, but you need to explicitly specify which phrases can be executed in the future (using sequencing operators much like C's semicolon). Effectively Haskell monads allow all imperative constructs except for backwards jumps (goto).
The Haskell IO Monad is a purely functional mechanism for ensuring that modifications of the RealWorld are done in the correct order. It is implemented to call system calls which have real side-effects, but wrapping IO in a monad ensures that you can still reason about the order the side-effects will occur in. Since Haskell is lazy, these side-effects won't actually be triggered until necessary, either because the program needs an input value or it exits.
(I can give examples if anyone wants, but the resources at haskell.org may be more helpful.)