Home | Forums | Articles | F@H
Help | Search | Members | Calendar | Forum Map | Cybervillage | Archive
Welcome Guest ( Log In | Register | Resend Validation Email )


>  IceTeks Forums -> Technology -> IceTeks Articles


  Reply to this topicStart new topic

>  Introction to Haskell
Track this topic | Email this topic | Print this topic
Red Squirrel
Posted: Jan 2 2005, 09:55 PM
Quote Post

ZOMG!

Group Icon

Group: Admins
Posts: 14 039
Member No.: 1
Joined: 18-December 02
Ice Cubes: 118907



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


--------------------
user posted image
http://www.redsquirrel.me my blog
http://www.uovalor.com AoS/ML Ultima Online Shard
PMEmail PosterUsers Website Top
wtd
Posted: Jan 4 2005, 04:21 PM
Quote Post

Liquid Nitrogen Blaster

Group Icon

Group: Ice Age Members
Posts: 157
Member No.: 532
Joined: 25-September 04
Ice Cubes: 11



First, thank you. I love it when people get something out of what I write. smile.gif

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.
PMEmail Poster Top
wtd
Posted: Jan 4 2005, 08:54 PM
Quote Post

Liquid Nitrogen Blaster

Group Icon

Group: Ice Age Members
Posts: 157
Member No.: 532
Joined: 25-September 04
Ice Cubes: 11



Oh, and when you get around to writing something in Haskell, and you have questions, feel free to ask. smile.gif
PMEmail Poster Top
wtd
Posted: Jan 9 2005, 03:12 AM
Quote Post

Liquid Nitrogen Blaster

Group Icon

Group: Ice Age Members
Posts: 157
Member No.: 532
Joined: 25-September 04
Ice Cubes: 11



In my introduction to Haskell I createded a simple function greeting, which takes a name as a string and formulates a greeting.

CODE
greeting :: String -> String
greeting name = "Hello, " ++ name ++ "!"


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)


The latter function I rewrote as:

CODE
greet :: String -> IO ()
greet name = putStrLn $ greeting name


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


Now, we can make a similar observation about the greeting function.

CODE
greeting :: String -> String
greeting name = "Hello, " ++ name ++ "!"


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 ++ "!")


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, " ++) . (++ "!")


Just as in the original, the function takes a string, appends "!" to it, then prepends "Hello, " to that.
PMEmail Poster Top
wtd
Posted: Jan 11 2005, 05:44 PM
Quote Post

Liquid Nitrogen Blaster

Group Icon

Group: Ice Age Members
Posts: 157
Member No.: 532
Joined: 25-September 04
Ice Cubes: 11



QUOTE (fred laforge @ Jan 11 2005, 10:03 AM)
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. smile.gif.
PMEmail Poster Top
wtd
Posted: Jun 4 2005, 07:10 PM
Quote Post

Liquid Nitrogen Blaster

Group Icon

Group: Ice Age Members
Posts: 157
Member No.: 532
Joined: 25-September 04
Ice Cubes: 11



QUOTE (HHH @ Jun 4 2005, 12:40 PM)
Hi,
how can I do a line skip in a String. I mean that one String ouput looks like this:

Hello, (line skip)
....

CODE
putStrLn "Hello"


The "Ln" means "line".

If you just want to skip a line...

CODE
putStrLn ""


Or you could make that a function.

CODE
skipLine = putStrLn ""
PMEmail Poster Top
genea
Posted: Dec 17 2005, 02:14 PM
Quote Post

Unregistered











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
Top
0 User(s) are reading this topic (0 Guests and 0 Anonymous Users)
0 Members:
« Next Oldest | IceTeks Articles | Next Newest »

Topic Options Reply to this topicStart new topic

 



[ Script Execution time: 0.0343 ]   [ 13 queries used ]   [ GZIP Enabled ]

< Home | Forums | Contact >