Page 1 of 1
Introction to Haskell
Posted: Sun Jan 02, 2005 8:55 pm
by Red Squirrel
Functional programming is fundamentally a very different way of thinking about programming. After all, we can learn several languages and pat ourselves on the back, but if the only real difference is syntactic, then we're not really being challenged.
http://www.iceteks.com/articles.php/haskell/1
Archived topic from Iceteks, old topic ID:2972, old post ID:24303
Introction to Haskell
Posted: Tue Jan 04, 2005 3:21 pm
by wtd
First, thank you. I love it when people get something out of what I write.
I see that kind of question a lot, though with a variation of different languages. For the most part, I think it's the kind of thing you have to determine for yourself.
That said, Haskell is just as Turing-complete as many other programming languages, and it isn't built especially for one particular type of task. It's a general purpose language, and so you can do just about anything your heart desires.
The only places I'd say it's not especially well-suited are the kind of problems where you need more direct hardware access. Thankfully such problems are few and far between.
Archived topic from Iceteks, old topic ID:2972, old post ID:24386
Introction to Haskell
Posted: Tue Jan 04, 2005 7:54 pm
by wtd
Oh, and when you get around to writing something in Haskell, and you have questions, feel free to ask.
Archived topic from Iceteks, old topic ID:2972, old post ID:24392
Introction to Haskell
Posted: Sun Jan 09, 2005 2:12 am
by wtd
In my introduction to Haskell I createded a simple function greeting, which takes a name as a string and formulates a greeting.
Code: Select all
greeting :: String -> String
greeting name = "Hello, " ++ name ++ "!"[code]
And then, I created a greet function which takes a name and prints the greeting for it.
[code]greet :: String -> IO ()
greet name = putStrLn (greeting name)[code]
The latter function I rewrote as:
[code]greet :: String -> IO ()
greet name = putStrLn $ greeting name[code]
Now, the argument "name" should appear quite redundant in that last example. It is. What if, instead, we could simply combine the two functions, "greeting" and "putStrLn".
Haskell provides an easy mechanism for doing so.
[code]greet :: String -> IO ()
greet = putStrLn . greeting[code]
Now, we can make a similar observation about the greeting function.
[code]greeting :: String -> String
greeting name = "Hello, " ++ name ++ "!"[code]
This is really two functions, since operators are just functions. Given the order of evaluation, this could be rewritten:
[code]greeting :: String -> String
greeting name = "Hello, " ++ (name ++ "!")[code]
Now, since we can partially apply functions - give them one argument, and get back a function which takes another argument and gives us the rest - we can rewrite this as:
[code]greeting :: String -> String
greeting = ("Hello, " ++) . (++ "!")[code]
Just as in the original, the function takes a string, appends "!" to it, then prepends "Hello, " to that.
[color=#888888][size=85]Archived topic from Iceteks, old topic ID:2972, old post ID:24665[/size][/color]
Introction to Haskell
Posted: Tue Jan 11, 2005 4:44 pm
by wtd
fred laforge wrote: great tutorial -- when will you post the next 6 lessons?
Heh. That one took a bit out of me, so there might just be smaller updates for a while.
.
Archived topic from Iceteks, old topic ID:2972, old post ID:24756
Introction to Haskell
Posted: Sat Jun 04, 2005 7:10 pm
by wtd
HHH wrote: Hi,
how can I do a line skip in a String. I mean that one String ouput looks like this:
Hello, (line skip)
....
Code: Select all
putStrLn "Hello"[code]
The "Ln" means "line".
If you just want to skip a line...
[code]putStrLn ""[code]
Or you could make that a function.
[code]skipLine = putStrLn ""[code]
[color=#888888][size=85]Archived topic from Iceteks, old topic ID:2972, old post ID:27241[/size][/color]
Introction to Haskell
Posted: Sat Dec 17, 2005 1:14 pm
by Anonymous
Very good article, with the part about type classes and the ability for a data type derived from a given class being able to automatically inherit the method (functions) from the class definition. I guess I missed that in the mountain of literature I had read and had been up till now missing the benefit of this info... I liked dobbing about with HASKELL and this just makes me believe, that it will have a bright future ahead, or one of the languages derived from it, such as CLEAN.
Thanks again.. and I too would like to see the next six!!
gene
Archived topic from Iceteks, old topic ID:2972, old post ID:33106