Real world Haskell programming [closed] - haskell

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
Having been an imperative developer for some years now, I had never had the urge to learn functional programming.
A couple months ago at last I decided to learn Haskell. It's quite a cool language, but I'm puzzled about how an event driven real app would be programmed in such a language. Do you know of a good tutorial about it?
Note: When I say "real app" I'm not talking of a real world, production ready app. I just mean a little sample app, just to get the grasp of it. I think something like a simplified version of the windows caculator would be great, and then perhaps something a bit more complex.

When you say "real world" examples you are presumably thinking about problems that are inherently sequential or stateful or do lots of I/O, right?
So, how about games?
Frag is a Quake clone, implemented for an undergraduate thesis (Functional Programming and 3D Games, Mun Hon Cheong, 2005). Here's a video of it in action.
Super Monao Bros. (formerly known as Super Nario Bros.) is, well, you can probably figure out which game it is a clone of. (This is the author's English language weblog.)
Purely Functional Retrogames is a 4-part series of blog articles about how to write games in a purely functional language, explained using Pacman as the example. (Part 2, Part 3, Part 4.)
Or, what about an X Window Manager, an extensible Emacs clone text editor or an IDE?
Then, there is the book, which even has your question already in the title: Real World Haskell and which is also available for free!
Another thing you might want to look at, is Functional Reactive Programming. (It is used in Frag, for example.) The interesting thing about FRP is that it allows you to look at the problem of, say, GUI programming from a very different angle. If you read the GUI chapter in the RWH book, you will see that it talks about how you can write a GUI application just like in C, only better. FRP OTOH allows you to write it in a totally different way that wouldn't even be possible in C.
A lot of times (I'm not saying that this is the case in your question, but it is a recurring pattern) when someone says "but can Haskell be used in the real world", what they are really saying is "I know how to do this in C, and in Haskell I cannot do it in exactly the same way, therefore it must be impossible in Haskell, therefore Haskell is not ready for the real world". But what they are missing out on, is that there might be a totally different and much better way to solve the problem. (It's like saying "Erlang doesn't have threads, therefore it cannot possibly be used to implement concurrent systems.") And FRP is just one example.

For a lightning talk today I have assembled this list of show-case Haskell applications, deliberately excluding anything that only targets programmers:
darcs (since 2002, 35 000 loc): Distributed
version control system with an innovative focus on changes instead
of states.
xmonad (since 2007, 30000 loc): Well known
tiling window manager with a huge library of layout and other
plugins. Made it into the list despite its configuration file being
a Haskell file.
hledger (since 2007, 9000 loc): Text-file
based double-ledger accounting tool, a clone of
ledger.
Raincat (since 2008, 2000 loc):
Platform game with a cat that does not want to get wet.
arbtt (since 2009, 2000 loc): My
automatic rule-based time tracker. Made it into the list as a
shameless plug; probably not that popular. It has now a proper web
page contributed by Waldir Pimenta.
detexify (since 2010, 500 loc): The
back end of the very useful LaTeX character command finder is
written in Haskell.
git-annex (since 2010, 28 000
loc): Manages your files and their location, a mixture of dropbox
and git. Written by famous Joey Hess, who made a living from it via
kickstarter
He is currently running a second round of
funding!
Nikki and the Robots (since 2010, 18 000
loc): Platform game with Nikki and, well, his robots. It was
produced as a commercial independent game and sold via a
pay-what-you-like scheme, but the company unfortunately closed down.
hoodle (since 2011, 13 000 loc): A
note-taking and PDF annotation software like
xournal.
Chordify (since 2012, ? loc): Analyses
music, e.g. from a YouTube video, and calculates the corresponding
guitar chords. Closed software, but supposedly written in Haskell.
(Also featured on my blog, and on the slides of the talk, with nice representative pictures of each program.)

xmonad is event driven (literally). It has a listener loop that wakes up on events, modifying an internal state modelling the X server, which is then rendered to the screen.
http://xmonad.org

I once found this irc bot written in haskell:
http://www.haskell.org/haskellwiki/Roll_your_own_IRC_bot

Here are some links as you requested.
This one explains a lot of things that doesn't 'make sense' to an imperative programmer about Haskell
Haskell Tutorial for C Programmers
This one is a very good easy to follow tutorial
Learn You a Haskell for Great Good
Raytracer written in Haskell
Haskell Raytracer
You can download Glasgow Haskell Compiler from here.
GHC

you should check out Real World Haskell. The book is freely available and shows how Haskell can be applied to real world problems. I wouldn't call it a tutorial, tho, as it is much more comprehensive.

Check out functional reactive programming.

Related

Why should I want to learn haskell? [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Haskell vs. procedural programming in the real world
Few times I heard people saying things like "Every programmer should know Haskell", "You aren't a programmer if you don't know haskell" and so on.
However, I'm not exactly sure if I should bother trying to get a brief understanding of that language or not. Playing around with interpreter (to get intuitive understanding of basics) will take at least few days (if not weeks), and I"m not exactly sure if the result will be worth it.
A bit of background (to get idea of my knowledge)
I've started programming as a kid (somewhere between 10 or 13 years ago) with programmable calculator, moved to basic, then onto non-x86 assembly (reimlementing multiplication and division, and writing self-modifying mouse driver was fun), pascal, delphi, now I'm using C++ almost exclusively. Know my way around unix shell, can write software in python and probably in anything (if I have a reference book nearby) that remotely resembles C++ or Pascal (i.e. blocks, similar flow control, etc). Specialization is 3D programming and shaders. "Fish in the water" with low-level operations (C-style memory allocation, pointers), less comfortable with extremely OOP approach (i.e. when classes are made for the sake of having classes). Almost completely self-taught. I.e. definitely not a newbie, but there are areas where I could improve.
So... what could I possibly gain from studying Haskell at this point? As far as I know, this language is not really widely used, as a result there probably is less libraries it can interface with (as it was with Delphi programming - you can do DirectX programming in delphi, if you really want, but you can't write 3dsmax/maya plugin with it (well, it is probably theoretically possible, but it certainly won't be easy)). I also don't think that I'll be easily able to plug a piece of Haskell code into game engine.
So, what kind of useful knowledge I can get from it?
P.S. I won't buy "if you learn another language, you'll probably learn something that will be probably useful" argument.
(Surely this is a duplicate question, but I can't find one now.)
You learn it in order to learn pure functional programming, which forces you to do many things in a completely different way. You get a new way of thinking. Programming without state? Programming without effects? Everything is lazy? Crazy type system with type inference? What the hell are monads? Your mind will be repeatedly blown, but in the end you come out with new perspectives/techniques from functional programming that are hard to otherwise pick up without going full-blown Haskell.
The problem with trying to be specific, is that trying to tell a non-Haskeller what they'll learn from Haskell is like trying to explain the color "green" to a blind guy.
A few years ago, many people were surprised to discover one of the introductory courses was being taught using Haskell as a/the programming language! Although I didn't have experience with Haskell, I had some background in Lisp and other Functional Programming languages.
I think the anecdote shows how knowledge can be useful when you least expect it.
In more practical terms: You may have noticed that CPU speeds hit a wall some years ago, and now the most practical way to pull more performance from computers is by installing multiple CPUs. Now it so happens that most if not all of the programming languages you know are essentially single tasking, and subject to the Von Neumann bottleneck. An obvious solution is parallel programming, but that can be very painful if the parallel parts of your program end up sharing state, i.e. memory - and this is most often the case.
It turns out that Functional Programming is a style that allows you to mostly circumvent the problems of parallel programming with shared state. Stated differently, it's fairly easy to write programs in the FP style that are "naturally" thread safe and suitable for parallel processing. Depending on the language, compiler and hardware you may even find (as I recently did) parts of your program running in parallel without ever having done any explicit coding for parallelism.
I'm frequently wrong, but my guess is that Functional Programming will turn out to be one of the hot programming paradigms of the future as parallel programming becomes more important and more difficult. Haskell may not turn out to be the language of choice - my personal favorite is currently Clojure - but it may well be worthwhile to take a look at one or more FP languages.
I also don't think that I'll be easily able to plug a piece of Haskell code into game engine.
If you only want to write 3D game engines then maybe there's not much point in learning Haskell.
If you want to be a well-rounded programmer capable of programming in multiple paradigms and you currently only know C-like languages then it is worth a look.
Every time you learn a new very different language it makes learning the next language easier because you're not just memorizing new syntax, you're also learning different ways of thinking about programming. If you try out a new language and you see some new feature you will more quickly understand it if you can relate it to another feature in a language you already know. The more languages you know the more likely it is that this new feature is similar to something you've seen before.
It's also handy to have many tools available in your toolbox. Some problems are better solved in one language than another. If you have 5 very different types of languages then you can select the best one for each problem. If you know only 2 or 3 very similar languages then some problems will be easy to solve, but others might be more difficult than if you used a language which is better at that specific task.
If 3D programming is your thing, you might be interested in some slides from a talk entitled The Next Mainstream Programming Languages: A Game Developer's Perspective by Tim Sweeney, the founder of Epic and technical director for the Unreal engine. He's spoken on the subject multiple times, and he clearly thinks very highly of Haskell.
There are several things you can get, mainly in the way you think about things. For example, it is interesting to notice what a minimal language is. If you go through SICP (and the same concepts apply to Haskell too), you will notice how you don't need loop syntax at all. You don't need any predefined functions that work on larger structures. You can define pretty much everything you need if you are given a cons constructor/deconstructor, or a way of defining one, and ability to recurse functions. You can define everything else yourself - and it is an interesting exercise to do so. And this is only the tip of the iceberg.
On a more practical level, for example, a couple of weeks ago I was doing OCaml homework and moaning "why doesn't this $%$%# language have call/cc!?!" My mind was blown when I noticed what I was thinking - I would never have missed it if I didn't know what it was, and I wouldn't known what it was if I didn't take a look at Scheme, Haskell, Ruby.
You can find many nice examples at ICFP contest; the one that really wowed me was this entry at this contest. They created a new language inside Haskell to solve their problem.
Learning a functional language will be quite a change from what you are used to.
So yes, you'll probably going to learn something useful ;)
I would say, if it's a chore don't do it. Otherwise start to read this and you should see after 10 mn if you are bored or if you are gripped and can't stop reading it.
Functional languages like Haskell are a different way of thinking about a problem. They are useful for learning and teaching data structures and algorithms, as they simplify those kinds of problem.
If you use the STL from C++, that has functional concepts that are similar to Haskell and other languages, so having a grounding in Haskell will help understand how the STL works.
If you use XSL:T to transform XML, that is very functional in its design.

What is so special about Smalltalk? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
In every technical publication, and on this site too, people are always comparing OO languages to Smalltalk. My experience is in Java: is Smalltalk so important that I should study it?
Smalltalk was one of the earliest object-oriented (OO) languages (with others like Simula and Eiffel) and can be said to be extremely "pure" in an OO sense:
Everything is an object and objects are only communicated with via the sending of messages
No primitives (no ints, booleans etc)
No control structures (no for, while, if etc). Sounds impossible but it's true!
No statics
It also pioneered some other, now common, stuff:
the virtual machine (and JIT compilation)
Debugging by inspection
"Hotswapping" running code
the modern IDE
Closures
Duck typing
Model-View Controller (MVC) architecture for UIs
Test-driven development (TDD) and agile methodology
And there are other things connected with Smalltalk which didn't really make it into the mainstream:
"Image"-based system rather than file-based.
Object-oriented databases
And it's fair to say that the Java collections API and the apache-commons collections API are heavily influenced by Smalltalk.
I wouldn't say that you should learn Smalltalk per se, but a familiarity with the fundamentals of these features (now present in many other languages) is surely advantageous to you.
Note that there are currently only 123 questions on here about the language, which was originally intended as an educational language (i.e. aimed at children) by its creator, Alan Kay. It is not particularly heavily used anymore. That's not to say it isn't used. JPMorgan, for example, has a large exotic derivatives risk-management system written in it.
Smalltalk has many brilliant innovations - things we're all taking for granted today, including:
being the first ever IDE
providing programmatic support for a GUI with a mouse If you learn Smalltalk GUI programming, you really will have understood MVC properly.
being built out of a small number of powerful ideas that work together extremely well
The Smalltalk way isn't to crash out on unexpected behaviour - it's to adapt. If you send a message to an object that doesn't understand it, the debugger comes up and invites you to write that method... so it provides excellent support for incremental development.
The IDE, the app that you're writing and your data are all part of the same system - so you can write your own tools and debug instrumentation far more easily.
The TDD toolset in Smalltalk is still better than any other language (see below).
Squeak Smalltalk has quite a bit of cutting-edge design research:
the morphic UI - you can get familiar with the concept of "liveness"
the seaside web framework - learn what a continuation server is and how it's radically different
Squeak has a strong connection with the OLPC software (one laptop per child) project - and could yet have a big influence on the world.
Find out what a "trait" is...
Play with the radical 3D immersive environment called Open Croquet.
Because Smalltalk is a smaller, simpler and more consistent language, with it's own built-in environment it's a much less confusing place to start teaching OOP. People who go this route end up being better Java, Ruby and C# programmers because they can learn basic OOP without all the messy inconsistencies of mainstream languages.
Some commercial Smalltalks have amazing, multi-node distributed OO database environments. I'm thinking about Gemstone.
Want to know the difference between Model-View-Controller and Model-View-Presenter - look at Dolphin Smalltalk...
The single most important reason to learn Smalltalk today is that extreme programming and scrum both got invented in the Smalltalk community... and the highly interactive style of programming you experience in Smalltalk is simpler, more powerful and direct than anything you can do with Java or C# or Ruby... and you can't really understand how well agile methods can work until you've tried to do extreme programming in Smalltalk. Few other languages (no mainstream ones anyway) have a comparable feature set.
... to really understand what TDD can be you need to use SUnit. JUnit just shows you where your tests failed. SUnit actually allows you click into the debugger at the point where the test failed and see the actual objects and how they're connected so you can see, live in the debugger how the code failed and fix it right there.
Yes, Smalltalk is so important you should study it. Why? You can understand object-oriented programming in pure, simple form. What people forget is that the Smalltalk-80 "Blue Book" has only about 90 pages devoted to the language—the language is just that simple. The other 300 pages talk about the predefined class hierarchy, which is a masterpiece of design for a class-based, object-oriented language that uses single inheritance. You will get a much deeper understanding of objects (e.g., classes are objects, and they have metaclasses, and so on off to infinity... except the knot is carefully tied to keep the system finite) than you would ever get from studying a hybrid language like Java or C++. Smalltalk matters not just because of its history but because of its simplicity:
Simple enough so you can understand the entire language and the libraries
Shows one idea (objects are all you need) pushed to its logical extreme
Everybody has something to learn from Smalltalk!
Smalltalk is one of the first two original OOP languages, the other being Simula-67. Consequently, there are two large families - the statically typed model centered around method invocation, pioneered by Simula (C++, Java, C# all belong here), and the dynamically typed model centered around message passing, pioneered by Smalltalk (Python, Ruby belong here).
Today, Smalltalk isn't particularly important on its own - there are some people still using it to write stuff, but it's definitely not mainstream. Learning it will give you some insight in how and why OOP evolved, however.
I spent about 5 minutes in a presentation at a conference last month on Smalltalk's history and influence. See Image-based development with Smalltalk. One of the more foreign concepts to today's programmers is the "image-based" development. There are some good analogies, including a DBMS and a spreadsheet.
Yes. Download the seaside one-click image, start using it with the tutorial from James Foster and you will learn at least:
how web applications should be build
how debugging is supposed to work
I agree with the others. I'm not sure if it's important per se, but it is COOL (imho).
I love that there are no loops or conditionals in the language. If-then-else is a message sent to a boolean object. Objects of type True do one thing, objects of type False do another. (Yes, True and False are subtypes of Boolean, with a single value each, true and false respectively).
It starts out being kind of counter-intuitive, but it does give you a very interesting, and deep, view of how OO programming should work...
Not only was it one of the first, Smalltalk remains to this day a paragon of OO language design. The more popular languages that came later — C++, Java, even Objective-C — all have more primitive object-orientation and are more restrictive than good old Smalltalk. Smalltalk had pervasive first-class objects, great support for runtime introspection, very natural use of duck typing and closures that worked better than I've seen in any non-functional language. I mean, we're talking about a language that had no native control structures (if, while, etc.) but was able to create them out of its object system in a way that worked seamlessly. How cool is that?
I wouldn't recommend Smalltalk for any intensive desktop app development these days (there just isn't a viable implementation IMO), but if you want to see how OO was meant to be and maybe pick up some ideas you can use in your apps, Smalltalk is a great place to look.
If you only know one object-oriented language you should consider learning a second and a third and a fourth in order to gain a broader perspective on programming with objects. Learning Smalltalk will stretch your brain because a lot of the familiar concepts we're used to in other languages (e.g. if-then-else, for(;;), while(), etc) are not there in Smalltalk. There are equivalents, obviously, but Smalltalk does things differently, and learning about different ways to do things is always a good idea.
Good luck.
I've just started to revive my interest in Smalltalk, and in my opinion, there are a few compelling things that are special about Smalltalk:
Highly productive development
environment
Built-in support for Agile/Extreme
programming methodologies
"Pure" object model
Easy to use graphics framework
None of these make it especially useful for people who are not in the software development business. My first exposure to it was when I saw a user interface for an embedded device prototyped on a PC using Smalltalk. This allowed the user interface to be modified and tested very quickly, and when completed, provided the embedded developers an "executable specification" that was far more precise than any document. I'm surprised I haven't seen this technique used far more often than I've observed in my travels during the last 20 years.
Using Smalltalk as a prototyping tool is where my interest lies: I think that given a new problem, different approaches to solving it can be tried and validated very quickly and easily in a Smalltalk environment, and once the desired solution is found it should be relatively mechanical to convert it to Java/C++/C# etc. etc. In fact, for repetitive sorts of things, it might well be possible to use Smalltalk to generate code for parts of the solution in some other target language.
The other thing about SmallTalk is that its alumni include Kent Beck and Ward Cunningham. Their work with SmallTalk spawned automated xUnit testing, software design patterns, CRC Cards and other practices which ed into XP/Agile, etc. So it could be argued that SmallTalk has been a major contributor to the modern programming landscape.
Just two comments:
Smalltalk is not object "oriented", is real objects, only objects and messages in the environment.
Smalltalk is not a language, is an environment that has a language (of the same name), but most of the "magic" here is thanks to the environment (the image).

Haskell vs. procedural programming in the real world [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
These days I'm getting seriously into functional programming.
While I'm really excited about Haskell and the possibilities it seems to offer, I can also see now that it is going to take me a while to learn. In an SO question on How to learn Haskell an answer states that it'll take months if not years to actually "master" it.
Now, I know C, PHP, some object oriented stuff, etc. And having been told that Haskell isn't much used out there in "the real world", will I be better off improving my skills in the regular languages I know? Is Haskell worth the struggle?
In this question on Why people think functional programming will catch on the conclusion seems to be that functional programming will "catch on". But surely procedural programming will stay on top, right?
EDIT: keparo nicely clarifies my question to: As opposed to procedural languages, will it be valuable for me to study Haskell and functional programming paradigms?
Haskell isn't as hard as people like to make out to learn. Haskell opens up a new world that you never knew existed for you. It's as valuable to learn as any other language. You might not find a job requiring you to do Haskell programming, but does that really mean a language isn't valuable?
Haskell will teach you a lot of new stuff, and it will show you how to program even better in the languages you /do/ work with. You can do your own personal projects in your spare time with it.
Haskell isn't really used much in the "real world" if you define "real world" as "cash generator". So if that is your objective, then you might have to rethink objectives :p
Also, I don't really like that part of chosen "how to learn haskell" answer. It takes months to years to master any language, not just Haskell. Depending on how you define "master". I can use Haskell to a pretty good degree of efficiency and I've only been learning it for a month, and I've been taking it slow even.
If nothing else, the change in mindset that learning Haskell provides will help you when you have to go back to using those procedural languages that still are used in the workplace.
The functional paradigm is beginning to make it's way into various mainstream applications and languages - Even C++ is going to be adding a (crippled) lambda in C++0x.
You may also want to look at some of the hybrid languages like Scala or OCaml. Scala is being used at Twitter, and OCaml is being used at Jane's Street in a financial trading platform.
I learned Haskell because it was by far the best functional language that I tried out of Scala, Clojure, OCaml and Scheme but I didn't seriously expect to use it for work.
As it turns out, it is perfect for those sorts of odd jobs that are too small for a team and would be just too time consuming in Java. So far, I've used it for ad-hoc data migrations i.e. mangling CSV exports into another format, batch conversions of XML (HXT is more concise and more powerful than XSLT), screen-scraping off the internet and software project estimating including modelling risk using the probability monad and producing optimum gantt charts using backtracking. This is all real work that needed doing, that I wouldn't have even bothered to try and do in Java as it would be a multi-day undertaking.
I now use it instead of Excel for anything vaguely mathematical as it is little more effort to create a list of values in haskell source in a text editor than it is to type them into Excel. Once in haskell, I can then do all sorts of magic like backtracking, probability distributions etc. that Excel can't do. If I need a graph then I spit the values out as CSV (2 lines of code) and load them into Excel.
The only downside is that it does take several months to get proficient, but worth the effort IMHO.
You probably shouldn't expect to use Haskell anywhere nearly as often as a C family language in professional settings. If the question is whether it will be valuable for you to study Haskell and functional programming paradigms, the answer is yes. You can apply your enriched understanding of programming to all of your work.
As opposed to procedural languages, will it be valuable for me to study Haskell and functional programming paradigms?
If having an expanded skill set is valuable, then: yes.
One advantage you might pick up: parallel and concurrent programming. Procedural languages of the past tend to have no clear notion of side effects, as a result writing parallel programs in them is difficult to do correctly. Functional languages (in particular, ones that limit side effects like Haskell) have a lot more to say about productive parallel programming.
Having that skill up your sleeve can't hurt.
As opposed to procedural languages, will it be valuable for me to study Haskell and functional programming paradigms?
Not unless you want to be miserable. Luke Plant says, in Why learning Haskell/Python makes you a worse programmer:
So, learning Python and Haskell has demoralised me and encouraged
me to write code that is bizarre and difficult to understand...
(This is not entirely a joke.)
I can see that functional programming can be a plus in a production environment if it's very easy to use by non functional code. MS could see that too when they came up with F# I guess.
Since they both compile to IL, you can handle problems that ask for a functional approach functional and use those solutions very easily in your procedural code.
In that way functional code can easily find its way in a production environment a bit at a time
Therefore, and since the userbase of MS is that big, my guess is that if F# will not catch on in the very near future, that Haskell won't either.
I think it's worth the struggle. It will help you to understand how problems are solved and not only how a computer works.
Maybe one particular problem is Haskell itself - As a purely functional language, it's kinda "hardcore" which may on the other hand even complicate things.
Functional programming instead may be extremely useful in a very pragmatic manner - Many OO/imperative languages have now included functional elements for this reason (Linq, anonymous functions, readonly values, function pointers/delegates, type-inference): You can concentrate on what should be done which allows you to express more in less code (that is even less error-prone).
Non-purely functional languages (standard functional languages) like Scala or F# can be integrated easily into existing Java or .NET-projects, so you can combine the benefits of both paradigms where they are needed. For typical advantages of functional languages, see this thread. Just think of extremely powerful parsing (Monadic parser combinators / Parsec) or concurrent programming that is possible with functional languages and you'll see how useful they are.
Broadening your horizons helps you be a better programmer no matter what language you happen to be using at the moment. You'll never look at programming the same way after you've written Lisp macros, for instance. After you begin to think in Haskell terms, you'll find yourself composing functions and wishing for closures in less advanced languages.
Judging from goodies in C# such as lambdas, type inference, closures, and so on, learning Haskell will give you a leg up on tomorrow's cutting edge in mainstream languages.
Some people enjoy programming in Haskell. If you can choose your environment, and enjoyment is a consideration, then maybe you should hop in.
Many programmers are not in position to choose their tools and enjoyment is not a factor for their choices. Many of them get to use C/Java/etc at their workplace for the "core project source", but then also choose or need to use Python for "scripts" such as build-scripts with SCons, other scripts that generate Java/etc code, testing systems, proofs-of-concepts, etc.. And in other places Python is also used in the "core project".
In 8 years, it will be Haskell, not Python, which will be "coming to you". But you can come to it sooner.
You can combine the use of functional programming and be pragmatic about the language.
All modern scripting languages s.a. JavaScript or Lua allow use of the functional paradigm.
The functional concept is coming on strong. Note the flurry of activity and interest around Ruby. I've also noticed a bit more interest in JavaScript beyond a mere browser scripting language lately. You can get ahead of the game by diving in now, though the time invested might not pay off this year or next.
It depends on your general game plan. Are you into programming as an end in itself or as a means to an end? If it's the former, go nuts with Haskell. If the latter, stick with mainstream, "employable" languages. Wait for Haskell to take off and then pounce.
Why procedural and not Object Oriented, not seen procedural being used for many years apart from C.
Commercially speaking. I would go with Java or C#. Doesn't really matter which they both pay well and the skills are interchangeable with other like minded languages such as python, Ruby and JavaScript.
Haskell is worth the time and effort, although it is very academic, some banks use it, although many in Europe and the UK are moving the code base over to F#.
I don't think FOP will be moving at great speeds commercially speaking. But the techniques are definitely making an appearance in the main stay languages. Especially with Multi-Core chip designs and making code run parallel on them.

High-level programming language for music composition [closed]

Closed. This question does not meet Stack Overflow guidelines. It is not currently accepting answers.
We don’t allow questions seeking recommendations for books, tools, software libraries, and more. You can edit the question so it can be answered with facts and citations.
Closed 4 years ago.
Improve this question
I would like to write an interactive song. It would contain state and logic. A listener/user should be able to modify some state vars using a GUI or a MIDI interface. Listener accessible vars don't have to directly represent tempo, pitch or any other music property. They would rather represent values that logic would process in order to make changes to the song.
Do I have to write such platform myself or something fitting my imagination already exists?
Look at cSounds and PureData.
If you are happy to use Java, check out JFugue.
I have tried PureData, CSound and SuperCollider.
CSound is very cumbersome to program in, and has had severe stability issues for my requirements (24bit/96kHz realtime low latency linux) in version 4.
PureData is graphical, which makes it even harder to keep code neat and tidy then with text files. Composing is a pain because you have to build your own composition GUI, which can be powerful, but as long as I'm my only user I find it's just faster to use text.
The winner hands down is SuperCollider, because it is a smalltalk inspired object oriented language which is quite pleasant to work with. It is split into an OSC controlled sound server, and the client language. I can recommend the sound synthesis server and using the language to create instruments without reservation for its excellent stability, great flexibility and incredible power. I've used it live on stage and the performance is incredibly good.
The score creation language suffers from many-hands syndrome; in lack of recent clear leadership there are too many ways to do too many things with too many limitations, but it is still better than CSound because at least you can use reasonable high level structures.
Still looking for a composition language that just gets it right.
Have a look at Strasheela:
It's a composition system based on the programming language Oz. Learning Oz isn't easy, as it it combines the functional and the logic programming paradigm. However if you liked the SICP book, then you will probably like it too.
Strasheela treats music composition as a Constraint Statisfaction Problem (CSP), and seeks "solutions" for it. It means that the music style is defined as mathematical constraints on integer numbers (finite domain), that must be statisfied, and the built-in constraint solving system computes the solutions "automatically".
P.S.: I cannot program in Oz, but I'm on my way of learning it.
See High level languages for Computer Music and Programming Languages used for music for help.
I am not sure if it covers what you are after for, but have a look at Java Sound API. For a FAQ about what it can do see here. The benefits are that is already bundled in the SDK and JRE and that is cross platform. Also, you could build the GUI using any Java toolkit.
If it weren't for the interactive bits, I'd suggest looking at Haskore or Nyquist, both effectively being DSLs for music generation.
Definitely take a look at Alex McLean's livecoding demos, though. It's more flexible and interactive as you can possibly imagine, using SuperCollider through OpenSoundControl.
Answer is for .NET:
I found something, checkout NAudio by Mark Heath, a great .NET music library I would say it should be contained in the BCL.
midi-dot-net is another great C# project by Tom Lokovic.
For music interaction, PureData, Max/MSP and OpenMusic (these two last are from IRCAM) are the best. PureData is freeware. Google them!
I don't really get what you want to do, but here is a list of some CL music software, both for composition and cognition: http://www.cliki.net/Music
You're looking for an Audio Programming Language. Another option you should consider is Processing - used by many artists and musicians for this type of work.
-Adam
Its a shame that none said about Chuck................
Chuck is a programming language that is specifically built for music/audio generation and composition.
You can download Chuck at http://chuck.stanford.edu
its a lot easier to use,and is a lot familiar to c,c++,java etc,however its easier to learn too.You can find at Coursera about chuck for free from California arts university,link here.

How can I use functional programming in the real world? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Functional languages are good because they avoid bugs by eliminating state, but also because they can be easily parallelized automatically for you, without you having to worry about the thread count.
As a Win32 developer though, can I use Haskell for some DLL files of my application? And if I do, is there a real advantage that would be taken automatically for me? If so, what gives me this advantage? The compiler?
Does F# parallelize functions you write across multiple cores and CPUs automatically for you? Would you ever see the thread count in Task Manager increase?
How can I start using Haskell in a practical way, and will I really see some benefits if I do?
It seems like the book Real World Haskell is just what you're looking for. You can read it free online.
F# does not contain any magic pixie dust that will pass functions off to different CPUs or machines. F#/Haskell and other functional programming languages make it easier for you to write functions that can be processed independent of the thread or CPU they were created on.
I don't feel right posting a link here to a podcast I participate in. It seems a little off, but in the Herding Code episode, where we talked with Matt Podwysocki, we asked the same question and he gave some interesting answers. There are also a lot of good links relating to functional programming in that episode. I found one link titled "Why Functional Programming Matters". That may provide some answers for you.
This might also be interesting:
"Real World Functional Programming"
Examples are in F# and C#, but the theory is fairly generic.
From what I've read (pre-release) it is definitely interesting, but so far I think it is making me want to stick more and more with C#, using libraries like Parallel Extensions.
You didn't mention, but I'm assuming, that you're using C++. One potentially easy way to get into functional is via C++/CLI to F#. C++ contains "magic pixie dust" (called IJW: It Just Works) to allow you to call into and out of managed code. With this, calling F# code is almost as simple as it is from C#.
I've used this in one program (FreeSWITCH), which is written entirely in C/C++. With a single managed C++/CLI (use the /clr switch), it magically transitions into managed code, and from there, I can go load my F# plugins and execute them. To make things even easier for deployment, F# can statically link all its dependencies, so you don't need to deploy the F# runtime files. One other thing that makes CLR code attractive is that you can pass managed code (delegates) to C code, and the runtime automatically makes a thunk for you.
If you decide to go the Haskell way, the feature you'll be looking for is FFI: Foreign Function Interface. However, I don't think it'll give you the same level of integration as C++/CLI with F#.
I'm currently learning Haskell myself. When you start out learning it, it doesn't seem very intriguing, because the learning experience is nothing like learning a language like C#.
It's a whole new world, but I noticed I could write very very complex expressions in just a few lines of code. When I looked back at the code, it was much more concise; it was small and tight.
I'm absolutely loving it! You can indeed write real-world programs that will be smaller, easier to maintain, and much more complex than most other languages allow. I vote for you to learn it!!
Since you mention Win32 and DLLs, I presume you're working with unmanaged code. In that case, GHC will work very well for you. Late last year I wrote a DDE server under Windows using FFI to talk to the Microsoft DDE libraries, and, surprisingly, it was an extremely pleasant experience (especially given that I'm a Unix guy).
Haskell's FFI is powerful (even supporting, e.g., callbacks into Haskell functions from C or other libraries), and having Haskell's type checking when writing C-level code is like a dream come true.
That last point is one of the major advantages of Haskell: the type system is amazing. That said, it's like any powerful tool; it needs time and effort to make good use of it.
So yes, it is possible to start out writing small bits of code in Haskell that link into the rest of your code (though you may find it easier to start with small Haskell programs that link to your other code), and it's well worth spending a fair amount of time learning about this and using it wherever you can. You may end up like me, planning a fairly major project tightly integrated with Windows code (in my case, a sophisticated Excel add-in) in Haskell.

Resources