Haskell

A place to discuss the implementation and style of computer programs.

Moderators: phlip, Moderators General, Prelates

User avatar
Myles.ONeill
Posts: 15
Joined: Thu Mar 12, 2009 10:07 am UTC
Location: Canberra, Australia
Contact:

Haskell

Postby Myles.ONeill » Thu Mar 12, 2009 10:39 am UTC

Hi I've just started formally studying programming at university (ANU) and to my shock/horror we are learning Haskell for the first semester.

I had never even heard of this language before then. Personally it seems fairly old and pointless to learn to me. What do you far more knowledgeable coders think?
Image

User avatar
Xanthir
My HERO!!!
Posts: 5410
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Haskell

Postby Xanthir » Thu Mar 12, 2009 11:46 am UTC

I'll let Berengal take this one for real, but from what I've seen, Haskell is one of the purest functional languages that is still useful. Learning it will give you an excellent insight into the hows and whatfors of proper functional coding, which is valuable. I get my functional kicks from Lisp, but Haskell seems quite powerful and interesting.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
zombie_monkey
Posts: 644
Joined: Mon Oct 16, 2006 1:26 pm UTC
Location: Bulgaria

Re: Haskell

Postby zombie_monkey » Thu Mar 12, 2009 12:01 pm UTC

I think learning Haskell as one of your first languages is an excellent idea, I wish I had studied it in the first semester or even in high school. It's good for your thinking even if you don't use it much after that.
Also, old in what way? I can't think of any context in which you could describe Haskell as "old".
It's a bit surprising that you have it in the first semester, but good. I think the course I took in it was in the third year.

User avatar
Myles.ONeill
Posts: 15
Joined: Thu Mar 12, 2009 10:07 am UTC
Location: Canberra, Australia
Contact:

Re: Haskell

Postby Myles.ONeill » Thu Mar 12, 2009 1:13 pm UTC

Our course teaches us Haskell in first semester then moves on to Java in second semester. I'm not sure what it will do in later years. I am actually studying science, with programming as a useful and interesting add-on, so I might not continue it past first year, but we'll see!
Image

User avatar
sparkyb
Posts: 1091
Joined: Thu Sep 06, 2007 7:30 pm UTC
Location: Camberville proper!
Contact:

Re: Haskell

Postby sparkyb » Thu Mar 12, 2009 3:35 pm UTC

Yeah, a lot of computer science programs start out with a functional language (mine did it the other way around, but same thing). There's not a ton of use of functional languages in the real world, which probably explains why you hadn't heard for Haskell. Even though they aren't as practical for real tasks, they are incredibly important theoretically. Once you learn functional programming you'll never think the same again. That your school covers this is a very good thing. A lot of places I know do it in Scheme or ML, but which functional language they choose doesn't really matter.

I personally don't know Haskell specifically, but Xanthir's right, as soon as Berengal sees this thread you're going hear more than you ever wanted to about how awesome it is. He's in love with that language.

User avatar
Xanthir
My HERO!!!
Posts: 5410
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Haskell

Postby Xanthir » Thu Mar 12, 2009 3:49 pm UTC

sparkyb wrote:Even though they aren't as practical for real tasks, they are incredibly important theoretically.

Note: the primary reason they aren't as practical for real tasks is that most coders are idiots, and thus too stupid to actually grasp anything beyond the copy/paste imperative paradigm. Since you have to work with these idiots in a corporate environment, you get to use a lowest-common-denominator language like Java.

Functional languages are practical as hell when everyone on your team understands them. This is especially true when you're a team of one.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
Briareos
Posts: 1940
Joined: Thu Jul 12, 2007 12:40 pm UTC
Location: Town of the Big House

Re: Haskell

Postby Briareos » Thu Mar 12, 2009 4:58 pm UTC

Xanthir wrote:Functional languages are practical as hell when everyone on your team understands them. This is especially true when you're a team of one.
Agreed.

i think haskell is a pretty cool guy, eh aviods side effects and doesn't afraid of anything.

But seriously, Haskell is tough to get into, but once you get it, you get it. Then it's pretty awesome to work with. As Xanthir said, if you're a team of one and can use whatever language you want, functional programming lets you quickly write small and correct programs. But when you have to collaborate with a lot of people it's easier to use imperative paradigms that everyone understands. Now let's just wait for Berengal's contribution to the thread.
Sandry wrote:Bless you, Briareos.

Blriaraisghaasghoasufdpt.
Oregonaut wrote:Briareos is my new bestest friend.

0xBADFEED
Posts: 687
Joined: Mon May 05, 2008 2:14 am UTC

Re: Haskell

Postby 0xBADFEED » Thu Mar 12, 2009 5:31 pm UTC

Xanthir wrote:
sparkyb wrote:Even though they aren't as practical for real tasks, they are incredibly important theoretically.

Note: the primary reason they aren't as practical for real tasks is that most coders are idiots, and thus too stupid to actually grasp anything beyond the copy/paste imperative paradigm. Since you have to work with these idiots in a corporate environment, you get to use a lowest-common-denominator language like Java.

Functional languages are practical as hell when everyone on your team understands them. This is especially true when you're a team of one.


I think it may be important to maintain a distinction between pure functional languages like Haskell and less pure functional languages like the ML variants when talking about "usefulness" or "usability". There are some tasks that are less suited to pure functional languages. Specifically, operations that are inherently stateful. With less pure languages these operations are more straight-forward at the cost of purity while in a pure functional language like Haskell you sacrifice grokkability to maintain purity.

For the less-pure functional languages I see no real usability gap since they let you fairly easily mix functional and imperative concepts.

It would be great if we could all work with outstanding programmers all the time but sadly that isn't the case.

User avatar
thoughtfully
Posts: 2253
Joined: Thu Nov 01, 2007 12:25 am UTC
Location: Minneapolis, MN
Contact:

Re: Haskell

Postby thoughtfully » Thu Mar 12, 2009 7:12 pm UTC

It's also worth pointing out that without side-effects (GUIs, print statements, poking hardware ports, network sockets, RAM, hard drives, blah, blah, blah) all your code is doing is spinning its computational wheels in an abstract space disconnected from the rest of the Universe. An elegant and beautiful arrangement, but hard to get practical use out of most of the time.
Image
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

User avatar
Briareos
Posts: 1940
Joined: Thu Jul 12, 2007 12:40 pm UTC
Location: Town of the Big House

Re: Haskell

Postby Briareos » Thu Mar 12, 2009 7:18 pm UTC

Haskell can do all those things; it just doesn't like to do them. Haskell lends itself to a coding style where you try to interact with the outside world as little as possible, and limit those impure interactions to as few functions as possible. You have one function that does the dirty work of getting some data and one function that prints some sort of result. In between you have nothing but referentially-transparent goodness.
Sandry wrote:Bless you, Briareos.

Blriaraisghaasghoasufdpt.
Oregonaut wrote:Briareos is my new bestest friend.

JonShapcott
Posts: 5
Joined: Thu Mar 12, 2009 7:22 pm UTC

Re: Haskell (longish)

Postby JonShapcott » Thu Mar 12, 2009 8:31 pm UTC

First of all, are you studying computer programming or computuer science? There's quite a big difference between the two. Learning Haskell suggests computer science to me, and Haskell is an excellent choice for that. I've been teaching myself Haskell for fun, and it just gets better and better the more I understand it. I am fortunate in having learnt scheme and ML at university, so the initial barrier wasn't to high.

There is at least one very good reason for studying Haskell first. Many people who enroll on courses have done some programming before. Some of them will have done quite a lot, but amost none will have met Haskell before. This forces everybody to learn at the same time, and much the same rate. The prevents those with no programming experience at all from feeling hopelessly left behind, at the cost of frustrating the more experienced.

One complaint you'll hear from the frustrated experienced programmers is "Haskell is useless! Nobody in industry uses it!" The simple response is to tell them to give up on computer science and find a computer programming course instead, because they obviously haven't understood that computer science is not just about training programmers for industry. The trickier response is to point out that it is in fact used in industry, and mostly by those who demand intelligent skilled programmers, so why do they think they aren't up to the task?

One warning. Monads will hurt initially, and trying to teach them is also difficult. Just realise that if the result type is monadic, then you can use the return function and do notation to make it look like you're writing imperative code. There's more to them than that, but that's a useful starting point. Monads aren't just for IO. although it will seem like that at first. The other use you'll meet fairly quickly is list comprehensions. Later on there will be monads for handling state without having to explicitly pass it around as function arguments, and eventually for handling mutable arrays when you really do need them.

Okay, I admit it, I'm an advocate. Bite me.

User avatar
Xanthir
My HERO!!!
Posts: 5410
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Haskell

Postby Xanthir » Thu Mar 12, 2009 8:41 pm UTC

Bah, no one'll fault you for being an advocate of functional languages here. I'd say maybe a quarter of the actives on this subforum are functional-language zealots to some degree.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
Myles.ONeill
Posts: 15
Joined: Thu Mar 12, 2009 10:07 am UTC
Location: Canberra, Australia
Contact:

Re: Haskell (longish)

Postby Myles.ONeill » Thu Mar 12, 2009 9:30 pm UTC

JonShapcott wrote:First of all, are you studying computer programming or computuer science? There's quite a big difference between the two. Learning Haskell suggests computer science to me, and Haskell is an excellent choice for that. I've been teaching myself Haskell for fun, and it just gets better and better the more I understand it. I am fortunate in having learnt scheme and ML at university, so the initial barrier wasn't to high.


The course is technically called 'Introduction to Programming and Algorithms' - however it is the beginner course for both computer science and programming degrees (I'm technically studying biology mainly myself).

What makes a functional language more apt for computer science?
Image

User avatar
b.i.o
Green is the loneliest number
Posts: 2519
Joined: Fri Jul 27, 2007 4:38 pm UTC
Location: Hong Kong

Re: Haskell (longish)

Postby b.i.o » Thu Mar 12, 2009 9:56 pm UTC

Myles.ONeill wrote:What makes a functional language more apt for computer science?

Functional languages form the foundation of computer science. I'm about to leave, but I'm sure someone else will elaborate for you.

User avatar
thoughtfully
Posts: 2253
Joined: Thu Nov 01, 2007 12:25 am UTC
Location: Minneapolis, MN
Contact:

Re: Haskell (longish)

Postby thoughtfully » Thu Mar 12, 2009 10:19 pm UTC

Myles.ONeill wrote:What makes a functional language more apt for computer science?

It's the side-effects. Or the lack thereof. When the functionality of a program can be expressed without invoking side-effects, it becomes a great deal easier to analyze, describe mathematically, and prove things about. It's got something to do with Lambda Calculus, but if if you don't know exactly what that is, you'll be fine.
Image
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

0xBADFEED
Posts: 687
Joined: Mon May 05, 2008 2:14 am UTC

Re: Haskell (longish)

Postby 0xBADFEED » Thu Mar 12, 2009 11:36 pm UTC

b.i.o wrote:Functional languages form the foundation of computer science. I'm about to leave, but I'm sure someone else will elaborate for you.


Functional languages aren't any more so the foundation of computer science than imperative languages.
Just as lambda calculus isn't any more the foundation of computer science than the Turing machine.
They both give a different perspective on roughly the same domain.

Rysto
Posts: 1460
Joined: Wed Mar 21, 2007 4:07 am UTC

Re: Haskell

Postby Rysto » Fri Mar 13, 2009 12:57 am UTC

*yawn*

Functional programming bigots have been going on about how much more efficient their languages are for decades, and yet imperative languages still rule the business world. What they fail to understand is that functional languages expressiveness for Computer Science rarely translates to the problems people solve in the real world.

Edit: Which isn't to say that I think that it's a bad idea to learn Haskell. I agree with the above poster who says that CS is a totally different discipline from programming. I just get tired of listening to people going on about how much better functional languages are because of how few lines they can solve Project Euler problems in.

stone915
Posts: 42
Joined: Wed Jan 07, 2009 4:31 am UTC

Re: Haskell

Postby stone915 » Fri Mar 13, 2009 2:37 am UTC

0xBADFEED wrote:I think it may be important to maintain a distinction between pure functional languages like Haskell and less pure functional languages like the ML variants when talking about "usefulness" or "usability". There are some tasks that are less suited to pure functional languages. Specifically, operations that are inherently stateful. With less pure languages these operations are more straight-forward at the cost of purity while in a pure functional language like Haskell you sacrifice grokkability to maintain purity.

For the less-pure functional languages I see no real usability gap since they let you fairly easily mix functional and imperative concepts.


Monads and do statements (which are just monads made prettier) let you do virtually anything you can do in an imperative language.

thoughtfully wrote:It's the side-effects. Or the lack thereof. When the functionality of a program can be expressed without invoking side-effects, it becomes a great deal easier to analyze, describe mathematically, and prove things about. It's got something to do with Lambda Calculus, but if if you don't know exactly what that is, you'll be fine.


Exactly. Put simply, a functional language is essentially math translated into a computer language. "Functional" refers to the idea of a mathematical function: you get the same result every time you run a program or call a function, no matter what, since all objects are immutable in Haskell.

I'd elaborate, but I have a final in discrete math tomorrow and a final for my Haskell course on Saturday, so I'll let berengal extol the virtues of Haskell.

0xBADFEED
Posts: 687
Joined: Mon May 05, 2008 2:14 am UTC

Re: Haskell

Postby 0xBADFEED » Fri Mar 13, 2009 3:16 am UTC

stone915 wrote:Monads and do statements (which are just monads made prettier) let you do virtually anything you can do in an imperative language.

I didn't say you couldn't do imperative-style programming in a pure functional language, just that they have to introduce some less-than straight-forward concepts to maintain cohesiveness. Compared to something like a 'ref' type in OCaml, monadic operations are considerably harder for a novice to understand.

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Haskell

Postby Berengal » Fri Mar 13, 2009 6:32 am UTC

Myles.ONeill wrote:Hi I've just started formally studying programming at university (ANU) and to my shock/horror we are learning Haskell for the first semester.

I had never even heard of this language before then. Personally it seems fairly old and pointless to learn to me. What do you far more knowledgeable coders think?

Haskell isn't old when compared to other languages. Python and Ruby are just about as old, C and C++ are much older by comparison. Java and C# are exceptions in the language world for being so much used at such an early age. Also, Haskell was mostly obscure until about 2003 when it started gaining more users and finally got out of obscurity.
Myles.ONeill wrote:Our course teaches us Haskell in first semester then moves on to Java in second semester. I'm not sure what it will do in later years. I am actually studying science, with programming as a useful and interesting add-on, so I might not continue it past first year, but we'll see!

Haskell kicks ass at scientific programming, because science uses math and functional programming is much closer to math than imperative. This means you can write your mathematical formulas almost directly, just substituting some of the weirder symbols, and have it execute.

What I like the most about Haskell is its purity. Being a lazy language, it couldn't suddenly allow side-effects in regular functions, because who knows in what order those function will execute, or if a function would execute at all. This forced the discovery of monads in programming languages, and it turns out monads are pretty damned neat. You probably won't have much to do with them in a single-semester course, but know this: Monads are an abstraction over models of computation. Got some stateful computations? There's a monad for that. Computations that can fail? There's a monad for that too. Non-deterministic backtracking computations (ala. prolog)? Sure, there's a monad for that as well. If you want to grok monads, the best place to start is probably the state monad. The IO monad, doing input-output, is actually just a state monad in the compiler, forcing the functions to be called once and only once and in the sequence specified.
There's a sort of meta-pattern in Haskell: If your code is ugly (e.g threading state), you put the ugly in a monad and forget about it.

All you need to know about monads as a beginner is that it's how you do IO and that you should probably stay away from it as much as possible. The biggest mistake programmers coming from imperative languages do is discover the IO monad and continue to do imperative programming. Haskell does interactions just fine, and if you find the language fighting you, you're doing it wrong.

Myles.ONeill wrote:The course is technically called 'Introduction to Programming and Algorithms' - however it is the beginner course for both computer science and programming degrees (I'm technically studying biology mainly myself).

What makes a functional language more apt for computer science?

Fuctional languages are more apt for anything with "science" in its name because it's closer to mathematics, as I already said. Programming degrees concern themselves with writing software in the industry, which means learning industry languages. Functional languages aren't used much there (but they are used. Linspire uses Haskell for all its systems programming, because shell scripts were ugly).

0xBADFEED wrote:Functional languages aren't any more so the foundation of computer science than imperative languages.
Just as lambda calculus isn't any more the foundation of computer science than the Turing machine.
They both give a different perspective on roughly the same domain.

Lambda calculus and turing machines are exactly the same domain. Curry-Howard isomorphism.
Rysto wrote:Functional programming bigots have been going on about how much more efficient their languages are for decades, and yet imperative languages still rule the business world. What they fail to understand is that functional languages expressiveness for Computer Science rarely translates to the problems people solve in the real world.

Have you read Paul Graham's "Beating the Averages"? He calls it the Blub Paradox.
0xBADFEED wrote:Compared to something like a 'ref' type in OCaml, monadic operations are considerably harder for a novice to understand.

Again with the monads: In the IO monad, the monad operations could be called simply "do this, then do that" and "do this, then take the result with you as you do that". Even pointers can be harder to understand than that.


Last note: My three main hacking languages are Java, Python and Haskell. Java I don't do by choice anymore, and when I have to it's painful. Haskell has a wonderful type system (which incidentally is actually turing complete, allowing for some neat compile-time tricks), but Java has the type-system of the devil, which only pupose is to serve the sadistic creators of the language in torturing poor programmer souls.
I do very little python programming as well these days, Haskell having taken over completely (I've become good enough that doing in Haskell what I would've done in Python is both easier and faster). Python isn't painful to program in, but the lack of distiction between pure and impure code and the lack of types makes me sort of uneasy when writing in it. (I'm surprised at the type thing, I used to be a dynamic type fanatic. Probably Java's fault that...)

I would've written something comprehendable, but I'm already ten minutes late for work.
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

User avatar
OOPMan
Posts: 314
Joined: Mon Oct 15, 2007 10:20 am UTC
Location: Cape Town, South Africa

Re: Haskell

Postby OOPMan » Fri Mar 13, 2009 9:49 am UTC

I'd be damn happy to get taught Haskell if I were you :-) Far more interesting than learning *groan* Java *groan*
Image

Image

User avatar
Myles.ONeill
Posts: 15
Joined: Thu Mar 12, 2009 10:07 am UTC
Location: Canberra, Australia
Contact:

Re: Haskell

Postby Myles.ONeill » Fri Mar 13, 2009 11:48 am UTC

Well I must say you guys have changed my mind, I'm quite happy to be learning Haskell now haha.

The course is going fairly slowly so far (it assumes absolutely no knowledge of how computers work >_>) but hopefully it will pick up soon!
Image

Tac-Tics
Posts: 536
Joined: Thu Sep 13, 2007 7:58 pm UTC

Re: Haskell

Postby Tac-Tics » Fri Mar 13, 2009 3:55 pm UTC

Haskell is a very interesting language. It's hard for the best reason something can be hard: it does everything you already know how to do in a way you had no idea was even possible. Monads are an amazing abstraction. Lazy evaluation is mind-bending (although sometimes perilous). Plus, you get to talk about infinite lists, which no other language can do! They also have the most amazing channel on all of IRC. The users are all so friendly and you'll never be short of help.

Haskell is not the end all. I had a year-long flirt with the language, but I got out of working with the community. Haskell is beautiful, but there's a lot I find unappealing about it. Haskell was designed by a committee. Languages defined by committee tend to suck. You need someone with vision and there is no one "leading" the future of Haskell. The last time someone touched the standard was 11 years ago. The proposal for Haskell Prime doesn't seem to have changed much in the last year.

I'm a particular person when it comes to syntax, so this is biased as hell, but I don't care for a lot of Haskell's syntax. When you define a function piecewise, you have to repeat the function name over and over. Because parameters can be deconstructed, they aren't given names and it gets confusing. {- ... -} are obscure delimiters for comments! Record syntax is totally lame. And the module system syntax in GHC is kind of dinky. I must admit, though, the indent syntax is nice and the monad notation is genius. Overall, I think there needs to be more built-in syntax sugar for writing side-effect-free code that looks imperative. There's nothing wrong with for-loops and local state.


Berengal wrote:I do very little python programming as well these days, Haskell having taken over completely (I've become good enough that doing in Haskell what I would've done in Python is both easier and faster). Python isn't painful to program in, but the lack of distiction between pure and impure code and the lack of types makes me sort of uneasy when writing in it. (I'm surprised at the type thing, I used to be a dynamic type fanatic. Probably Java's fault that...)


Very few programming languages make the pure-impure distinction. It's not really a Problem with Python but a Feature? of Heaskell. That's Feature? with a question mark, because even though purity is very awesome, sometimes you just wanna throw some shit together and have it work. That is the real magic of dynamically typed languages like Python, Ruby, or PHP.

Type checking is a hard problem. The type system of ANY programming language will always have its quirks. No one type system can work for every program. There's always going to be work arounds or type casts in one form or another. Generally speaking, dynamic languages are superior for short programs. Shell scripts, code that changes frequently, and text processing stuff is very easy to throw together. They are usually more powerful at runtime, too, allowing inspection and reflection and changing the types while the script is being debugged.

With larger projects, though, static typing is nicer. You can mentally type check any program, but a compiler isn't going to make any mistakes, even if the program spans a thousand files. You sacrifice flexibility for reliability, but when you have a large application, restricting flexibility has benefits. If you are relying on code in another part of your system, you want that code to Just Work. It's best not to write clever code when other modules are relying on you. You can't go around changing interfaces, because the type checker will say no.

User avatar
thoughtfully
Posts: 2253
Joined: Thu Nov 01, 2007 12:25 am UTC
Location: Minneapolis, MN
Contact:

Re: Haskell

Postby thoughtfully » Fri Mar 13, 2009 4:13 pm UTC

Tac-Tics wrote:Plus, you get to talk about infinite lists, which no other language can do!

Python has infinite lists, since v2.2. Inspired by Haskell, as I understand it :)

Code: Select all

def fibonacci():
   a, b = 1,1
   yield a

   while True:
      a,b = b,a+b
      yield a
Last edited by thoughtfully on Fri Mar 13, 2009 4:30 pm UTC, edited 2 times in total.
Image
Perfection is achieved, not when there is nothing more to add, but when there is nothing left to take away.
-- Antoine de Saint-Exupery

Tac-Tics
Posts: 536
Joined: Thu Sep 13, 2007 7:58 pm UTC

Re: Haskell

Postby Tac-Tics » Fri Mar 13, 2009 4:19 pm UTC

thoughtfully wrote:
Tac-Tics wrote:Plus, you get to talk about infinite lists, which no other language can do!

Python has infinite lists. Inspired by Haskell, as I understand it :)


A generator isn't a list. It has a different type ;-)

User avatar
Xanthir
My HERO!!!
Posts: 5410
Joined: Tue Feb 20, 2007 12:49 am UTC
Location: The Googleplex
Contact:

Re: Haskell

Postby Xanthir » Fri Mar 13, 2009 4:38 pm UTC

Nod. I use generators in my Lisp code, but that doesn't make it an infinite list. You can't access previous elements, frex, without storing it explicitly into a new list.
(defun fibs (n &optional (a 1) (b 1)) (take n (unfold '+ a b)))

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Haskell

Postby Berengal » Fri Mar 13, 2009 5:45 pm UTC

Tac-Tics wrote:Plus, you get to talk about infinite lists, which no other language can do!

There are other lazy languages, though Haskell is indeed the most popular one. Python generators aren't lists, as evidenced by the generator forgetting all about its previously returned values (except the last one is usually saved as an internal state). It's quite easy to build lazy, infinite lists with user_list and generators though (and a small readjustment in coding style when writing the functions working on them). It's not exactly idiomatic code, but it's not too hackish either, and doesn't mess up your other code too much. Just sayin'...

Tac-Tics wrote:Overall, I think there needs to be more built-in syntax sugar for writing side-effect-free code that looks imperative. There's nothing wrong with for-loops and local state.

There's always 'runState initialState $ do ...'
What's wrong with for-loops is they're too general. I personally prefer splitting its functionality into map, filter, foldr, iterate, unfoldr and until, making code easier to read. If your loop needs to use some unholy combination of those, then fine, but in the majority of cases one or two of these specialized function will do and make your code clearer.

Tac-Tics wrote:
Berengal wrote:I do very little python programming as well these days, Haskell having taken over completely (I've become good enough that doing in Haskell what I would've done in Python is both easier and faster). Python isn't painful to program in, but the lack of distiction between pure and impure code and the lack of types makes me sort of uneasy when writing in it. (I'm surprised at the type thing, I used to be a dynamic type fanatic. Probably Java's fault that...)


Very few programming languages make the pure-impure distinction. It's not really a Problem with Python but a Feature? of Heaskell. That's Feature? with a question mark, because even though purity is very awesome, sometimes you just wanna throw some shit together and have it work. That is the real magic of dynamically typed languages like Python, Ruby, or PHP.

I frequently write small scripts in Haskell, most only having 'main = interact doTheThing' and then lots of pure code. I still write some scripts in python from time to time, and I can't really say which of them is the best scripting language. They tend to have slightly different focuses though, with python doing somewhat more system interaction (reading files etc) than my Haskell scripts, while scripts that do heavier data transformation are usually written in Haskell. For easy one-shot scripts I use Bash, which still is the ultimate in scripting languages. I do find Haskell to be the superior hacking language though, because it has a slightly easier edit->interpreter->repeat pipeline.

Tac-Tics wrote:Type checking is a hard problem. The type system of ANY programming language will always have its quirks. No one type system can work for every program. There's always going to be work arounds or type casts in one form or another. Generally speaking, dynamic languages are superior for short programs. Shell scripts, code that changes frequently, and text processing stuff is very easy to throw together. They are usually more powerful at runtime, too, allowing inspection and reflection and changing the types while the script is being debugged.

Types don't get in my way in Haskell (or Python for that matter). It could be I'm just used to them in Haskell, but they help me think about what I'm doing, which I find helpful even for small things. When I first started learning Haskell, I came from a mostly Java∕Python background and found Haskell's type system to be inbetween those two, mostly leaning to the Python side. I now realize it's even more strict than Java's, and I've come to a small conclusion: Types are a problem because you can't not have them (weak typing) because that makes no sense (square root of a string anyone?), but they tend to get in the way causing head wounds and bloody desks (Java style static typing). To solve that problem you can either have types and then ignore them (dynamic typing) or you can do it the Right Way (static HM type inference). Both make sense, and I won't claim one is better than the other, but my personal preference is static type inference.

Tac-Tics wrote:With larger projects, though, static typing is nicer. You can mentally type check any program, but a compiler isn't going to make any mistakes, even if the program spans a thousand files. You sacrifice flexibility for reliability, but when you have a large application, restricting flexibility has benefits. If you are relying on code in another part of your system, you want that code to Just Work. It's best not to write clever code when other modules are relying on you. You can't go around changing interfaces, because the type checker will say no.

Fun fact: I run into complexity related issues much earlier in Java than I do in Python. I see this as very much anecdotal though, because people keep telling me static types are good for complexity, but I still don't really grok that fact.

Tac-Tics wrote:Haskell is a very interesting language. It's hard for the best reason something can be hard: it does everything you already know how to do in a way you had no idea was even possible.

I have a somewhat different story: Appart from the minor hurdle of IO and monads, I thought the basics of Haskell were easy and got them fast and solved about 30 project euler problems in a few weeks. The reason I quickly found it hard was because it then started doing things that are "impossible" in the other languages I knew: It has a steep learning curve not because it's hard, but because it's so easy you'll be learning too fast. (My python style was already leaning towards functional programming when I started Haskell, so while there were some interesting surprises, I recognized many things as simply extremes of some of my python idioms.)

(If I seem to disagree with much of what you said, I'm not really. Think of it as providing a different perspective).
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

0xBADFEED
Posts: 687
Joined: Mon May 05, 2008 2:14 am UTC

Re: Haskell

Postby 0xBADFEED » Fri Mar 13, 2009 8:00 pm UTC

Berengal wrote:
0xBADFEED wrote:Functional languages aren't any more so the foundation of computer science than imperative languages.
Just as lambda calculus isn't any more the foundation of computer science than the Turing machine.
They both give a different perspective on roughly the same domain.

Lambda calculus and turing machines are exactly the same domain. Curry-Howard isomorphism.

Of course I know that Turing machines and lambda calculus are isomorphic. My choice of words: "roughly the same domain" was somewhat poor. What I meant was that even though they are of equivalent power, like imperative languages and functional languages, some concepts are more natural to express in one than the other.

Berengal wrote:
0xBADFEED wrote:Compared to something like a 'ref' type in OCaml, monadic operations are considerably harder for a novice to understand.

Again with the monads: In the IO monad, the monad operations could be called simply "do this, then do that" and "do this, then take the result with you as you do that". Even pointers can be harder to understand than that.

Yes, the "do" notation is very nice and hides a lot of the complexity. However, knowing how to use the 'do' notation for basic IO and understanding what is going on behind the scenes is completely different. You can explain to someone everything there is to know about OCaml's 'ref' type in less than 10 minutes and they will have an understanding of not just how to use it but how it works. The same can't be said for monadic operations. It takes a considerably longer time to wrap your head around. I'm not knocking monads or Haskell. I'm just saying that the cost for keeping the cohesive purity of Haskell is the introduction of a somewhat complex control mechanism and that this can be stumbling block for novice programmers when compared to an impure functional language like the ML variants or Scala.

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Haskell

Postby Berengal » Fri Mar 13, 2009 8:41 pm UTC

I wasn't talking about the 'do' notation, but the more primitive (>>=) and (>>). At first, I was indeed somewhat puzzled by them, but despite my head-scratching I managed to do IO just fine and didn't really lose anything compared to imperative languages. I gave up on understanding monads, instead treating IO as simple values just like any other value, except that it was also a computation that would be executed when put somewhere in the sequence chain starting at 'main', and now that I do know monads I know I didn't really miss out on anything as far as simple IO is concerned.
The problem is that when newbies learn about IO they also hear this word "monad" and think it's (rightfully) relevant and (wrongfully) essential. When they then try to figure out what a monad is they get confused and somehow manage to conclude that IO in Haskell is complicated. It isn't, and you get just the same power of IO as in other languages as long as you know about 'do' notation (and it's simple relation to (>>=) and (>>) (which, as I said, should be simple enough to understand for IO)). Monads are awesome, but understanding them just gives you extra expressive power (not related to IO at all), not knowing them doesn't hamper your IO capabilities. Monads are a generalization, of which IO is a specialization. You don't have to know how stuff works in the general case to understand how it works in a single special case.

This is what I meant by the steep learning curve comment previously. Haskellers like to throw highly theoretical research papers in your face. "I'll now spend five minutes telling you how to do this common task in Haskell, then spend the rest of the hour explaining how it is really just a special case of this higher-order generalization, how they relate to eachother and some pretty awesome things we can do with your newfound knowledge using lots of weird mathy symbols."
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

JonShapcott
Posts: 5
Joined: Thu Mar 12, 2009 7:22 pm UTC

Small aside on detail

Postby JonShapcott » Sat Mar 14, 2009 12:34 pm UTC

Berengal wrote:There's always 'runState initialState $ do ...'

I'm not sure about that, and I hate to break into a nice discussion with a detail nitpick, but I'm pretty sure that the initial state is the second argument to runState. If I've misunderstood something, then please point it out, if not, then 'flip runState initialState $ do ...' would be what you'd want. The way you've written it would be more appealing though.

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Haskell

Postby Berengal » Sat Mar 14, 2009 1:03 pm UTC

You're right, the initial state comes second. When you think about it, both orderings make sense though, as the current ordering allows you to do e.g. 'until reachedFinalState (evalState stateComputation) initialState'. (evalState by the way simply extracts the final state only and ignores the result of the computation).
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

sakeniwefu
Posts: 170
Joined: Sun May 11, 2008 8:36 pm UTC

Re: Haskell

Postby sakeniwefu » Mon Mar 16, 2009 2:23 am UTC

Haskell programs do have a single unfortunate side effect - They send their programmers in a holy internet crusade to explain the language's superiority in lengthy and dense dissertations. Monads don't save you from that.
:wink:

0xBADFEED
Posts: 687
Joined: Mon May 05, 2008 2:14 am UTC

Re: Haskell

Postby 0xBADFEED » Mon Mar 16, 2009 4:39 am UTC

sakeniwefu wrote:Haskell programs do have a single unfortunate side effect - They send their programmers in a holy internet crusade to explain the language's superiority in lengthy and dense dissertations. Monads don't save you from that.
:wink:

Seriously, Haskell programmers are the Prius drivers of the programming world. Or is that Lispers?

User avatar
Berengal
Superabacus Mystic of the First Rank
Posts: 2707
Joined: Thu May 24, 2007 5:51 am UTC
Location: Bergen, Norway
Contact:

Re: Haskell

Postby Berengal » Mon Mar 16, 2009 4:45 am UTC

0xBADFEED wrote:
sakeniwefu wrote:Haskell programs do have a single unfortunate side effect - They send their programmers in a holy internet crusade to explain the language's superiority in lengthy and dense dissertations. Monads don't save you from that.
:wink:

Seriously, Haskell programmers are the Prius drivers of the programming world. Or is that Lispers?

Are you kidding? Hybrids use gas just like every other car! We haskellers form a dance-circle and wish for the magical fairies to moves us around, which is much more eco-friendly and more in tune with the earth-spirit as well. It's true, I've got the papers to prove it!
It is practically impossible to teach good programming to students who are motivated by money: As potential programmers they are mentally mutilated beyond hope of regeneration.

turboxs
Posts: 1
Joined: Mon Mar 16, 2009 7:09 am UTC

Re: Haskell

Postby turboxs » Mon Mar 16, 2009 7:11 am UTC

Haskell is awesome! Its pure functional goodness makes my heart sing. But everyone else I know hated it.


Return to “Coding”

Who is online

Users browsing this forum: No registered users and 11 guests