Originally Posted by
Queatrix
Woah, Haskell is a lot harder than I thought it would be.
It really isn't, it just seems totally mind-blowing when you first get into it (and it really is when you've never done functional programming before.) It took a while of just writing random and interesting little code snippets before I got a good handle on it.
While learning Haskell, I probably wrote more little dumb programs and snips of code to get the hang of it than any other language I've done the same with, because I find programming in Haskell quite fun and interesting. You'd be really suprised at what you can make using some of the languages features.
Is there anything that one might acomplish faster or at all with Haskell than they would with c/c++?
Here's an easy and basic implementation of a unix cat program:
Code:
[austin@continuum haskell]$ cat cat.hs
module Main where
main = interact id
[austin@continuum haskell]$ ghc cat.hs
[austin@continuum haskell]$ ./a.out < cat.hs
module Main where
main = interact id
[austin@continuum haskell]$
If you wanted a program that would output the lines in reverse:
Code:
module Main where
main = interact (unlines . reverse . lines)
Or if you wanted every line in the file reversed and outputted in regular order:
Code:
module Main where
main = interact (unlines . (map reverse) . lines)
Once you get used to it, you really, really begin to appreciate things in functional programming like higher order functions and monads. And there're even other benefits that're simply side effects of a functional programming language such as Haskell. Example: due to Haskell being a pure functional programming language, i.e. it eschews side effects (no global variables), haskell code is referentially transparent (which basically means that "f(x) = f(x)" in all cases), which is a factor in parallel execution of code on things like multiple cores.