[Site Home] [Forum Home] [Articles] [File DB] [News Archives]

IceTeks Articles -> Introction to Haskell


(View original topic)


genea - Dec-17-2005 server time
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

nXg - Aug-11-2005 server time
is it possible to access text files from the internet? if yes, how and is there a way to check file properties (such as last modification date-time)?

nXg

wtd - Jun-04-2005 server time
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 ""

HHH - Jun-04-2005 server time
Hi,
how can I do a line skip in a String. I mean that one String ouput looks like this:

Hello, (line skip)
....

wtd - Jan-11-2005 server time
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.

fred laforge - Jan-11-2005 server time
great tutorial -- when will you post the next 6 lessons? :-)

wtd - Jan-09-2005 server time
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.

wtd - Jan-04-2005 server time
Oh, and when you get around to writing something in Haskell, and you have questions, feel free to ask. smile.gif

wtd - Jan-04-2005 server time
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.

Lightning - Jan-04-2005 server time
That was really great. Thanks very much!

I might just use Haskell to make some file IO tools I need for other projects. Looks much simpler and faster to code than C++.

I'd really like to know what kind of programs are best suited to be coded in Haskell though?

Cheers,
Cam

Red Squirrel - Jan-02-2005 server time
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

(Showing 50 last posts, newest on top)