Introction to Haskell

Anything technology related that does not fit in other categories
Locked
User avatar
Red Squirrel
Posts: 29209
Joined: Wed Dec 18, 2002 12:14 am
Location: Northern Ontario
Contact:

Introction to Haskell

Post 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
Honk if you love Jesus, text if you want to meet Him!
wtd
Posts: 157
Joined: Sat Sep 25, 2004 7:21 pm

Introction to Haskell

Post 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
wtd
Posts: 157
Joined: Sat Sep 25, 2004 7:21 pm

Introction to Haskell

Post 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
wtd
Posts: 157
Joined: Sat Sep 25, 2004 7:21 pm

Introction to Haskell

Post 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]
wtd
Posts: 157
Joined: Sat Sep 25, 2004 7:21 pm

Introction to Haskell

Post 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
wtd
Posts: 157
Joined: Sat Sep 25, 2004 7:21 pm

Introction to Haskell

Post 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]
Anonymous

Introction to Haskell

Post 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
Locked