Haskell

Yes or No?

  • (2 Pages)
  • +
  • 1
  • 2

24 Replies - 1256 Views - Last Post: 12 April 2009 - 12:55 PM

#16 JonBernal  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 199
  • Joined: 14-March 09

Re: Haskell

Posted 10 April 2009 - 06:35 AM

haha

Well, I guess we all know who's getting
old and not dealing with the future! D:

hahaha jk

Well idk, I'm still waiting on my book, its
now 2 days late. Which is frustrating...
But I'm hoping something good out of this,
I'm excited :D
Was This Post Helpful? 0
  • +
  • -

#17 KYA  Icon User is offline

  • g++ jameson.cpp -o beverage
  • member icon

Reputation: 3093
  • View blog
  • Posts: 19,139
  • Joined: 14-September 07

Re: Haskell

Posted 10 April 2009 - 06:10 PM

View PostNeoTifa, on 10 Apr, 2009 - 06:21 AM, said:

Seriously, though, recursion makes my brain explode. I prefer iteration. That way I can see wtf is going on in every step.


That really doesn't make sense. Recursion is iteration of itself. Using a print statement either way shows what's "going on".
Was This Post Helpful? 0
  • +
  • -

#18 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5780
  • View blog
  • Posts: 12,594
  • Joined: 16-October 07

Re: Haskell

Posted 11 April 2009 - 04:00 PM

I think the problem with recursion is it's often taught as "advanced." It's applied to complex problems where recursion is most applicable, like divide and conquer. The standard "towers of hanoi" solution, while I understand it, still makes my brain hurt and gives me serious dyslexic flashes trying to trace it.

Recursion isn't hard, it's just not as linear as iteration. Here's an example of recursion that's basically iterative.
// print n..1
void iterPrint(int n) {
	while(n>0) {
		printf("%d ", n);
		n--;
	}
}

// print n..1
void recurPrint(int n) {
	if (n>0) { 
		printf("%d ", n);
		recurPrint(n-1);
	}
}



Here's an example, going the other direction. In this, recursion gets to work for us. Note how almost nothing has changed in the recursive version.

// print 1..n
void iterPrintFwd(int n) {
	int i;
	for(i=1; i<=n; i++) {
		printf("%d ", i);
	}
}

// print 1..n
void recurPrintFwd(int n) {
	if (n>0) { 
		recurPrintFwd(n-1);
		printf("%d ", n);
	}
}



Recursion offers possibility of one of those "eureka" moments in programming. If you understand how those two functions work, you'll be ready for more complex problems.
Was This Post Helpful? 0
  • +
  • -

#19 Martyr2  Icon User is offline

  • Programming Theoretician
  • member icon

Reputation: 4316
  • View blog
  • Posts: 12,095
  • Joined: 18-April 07

Re: Haskell

Posted 11 April 2009 - 04:23 PM

Just to add onto what baavgai said about being taught as "advanced" it is also being taught in situations where it shouldn't be. Recursion for a Fibonacci sequence for instance is a bad idea. The same process could be done with an iterative loop which is faster because of lacking the overhead of a function call.

But having said that, recursion has its place in specialized situations. I find it great for tree traversals etc. But it should be limited to those special cases where it actually adds value.

As for the OP.... just another language as usual. The world has too many of them as it is.
Was This Post Helpful? 0
  • +
  • -

#20 JonBernal  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 199
  • Joined: 14-March 09

Re: Haskell

Posted 11 April 2009 - 05:33 PM

Mm, Just an other language then?
Was This Post Helpful? 0
  • +
  • -

#21 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5780
  • View blog
  • Posts: 12,594
  • Joined: 16-October 07

Re: Haskell

Posted 11 April 2009 - 08:06 PM

View PostJonBernal, on 11 Apr, 2009 - 06:33 PM, said:

Mm, Just an other language then?


They all are. :P

I have to heartily agree with Martyr, Fibonacci simply awful for recursion. That said, for a functional language, it many not be. The guts functional languages tend to optimized the sting out of recursion. Otherwise, they would honestly suck.

I felt guilty about the code above. For the sake of completeness, and discussion, I wanted to show a Haskell example But, well, I didn't know Haskell. Took a bit, a true Haskell expert may call it drek; I'm cool with that. In Haskell, the recursive number lister might look like this:

recurPrintFwd n | n<=0 = [] | otherwise = recurPrintFwd (n-1) ++ show n ++ " "


Was This Post Helpful? 0
  • +
  • -

#22 JonBernal  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 199
  • Joined: 14-March 09

Re: Haskell

Posted 11 April 2009 - 09:13 PM

haha, OCD Maybe?
Was This Post Helpful? 0
  • +
  • -

#23 baavgai  Icon User is offline

  • Dreaming Coder
  • member icon

Reputation: 5780
  • View blog
  • Posts: 12,594
  • Joined: 16-October 07

Re: Haskell

Posted 12 April 2009 - 04:22 AM

View PostJonBernal, on 11 Apr, 2009 - 10:13 PM, said:

haha, OCD Maybe?


Lol, hardly. If so, my desk would have much less crap on it. More OPD, where the P is Programming or maybe Puzzle.

The reason some languages exist at all is that programmers enjoy programming. Given a new toy, the first question is can it do all the stuff the old toy did. What does it do better, what worse.

People write programs to solve problems, but there is a satisfaction in the writing. People don't sit down to solve a jigsaw puzzle just because they want to see what it looks like when they're finished.

In the end, the real reason to learn a new computer language you have no ready use for is entertainment. Because you can. It's not really a bad reason. ;)
Was This Post Helpful? 0
  • +
  • -

#24 mostyfriedman  Icon User is offline

  • The Algorithmi
  • member icon

Reputation: 727
  • View blog
  • Posts: 4,473
  • Joined: 24-October 08

Re: Haskell

Posted 12 April 2009 - 07:42 AM

i agree with baavgai and Martyr2, recursion is great for some problems, tree traversals using iterations are painful to the programmer, a lot of code to write and harder to think of.
Was This Post Helpful? 0
  • +
  • -

#25 JonBernal  Icon User is offline

  • D.I.C Head

Reputation: 3
  • View blog
  • Posts: 199
  • Joined: 14-March 09

Re: Haskell

Posted 12 April 2009 - 12:55 PM

Haha

Very true man.
I love programming for that simple reason
that when i'm having trouble programming
something and then i get it to work
It just feels awesome :D
Was This Post Helpful? 0
  • +
  • -

  • (2 Pages)
  • +
  • 1
  • 2