Powered By Blogger

2011年6月9日星期四

The Begin of Haskell

I have spent almost a week to learn how to use this language and finally I've developed the Baccarat in Haskell. Now I think it's really necessary for me to arrange my mind,which is messed up by this language.

First of all, this language is totally differnet with the previous language I've developed with, such as the OOP language: java, c++ and python or the imperative language:c. Actually it belongs to the functional language. In another way, functions in this language is " the first class", such as the variables or the parameters in OOP or imperative language. That is, you can take the function as the parameter or variable and do what the parameter or the variable can do.

Second, this language is called "purely". What purely means is that there is no side effect when you are programming, even if you are doing some  IO operations.


What's the next, in this language, there is no loop and instead of loop, it uses recursion. This point is the one I can't understant at the very beginning. Such as a loop writen in C:
while(a>0)
...
In Haskell, there is no corresspoding defination of loop, so, you can only write the above code like the following:
func a =
 if (a==0)
 ....
func(a-1).
You see, you have to declare a function and use recursion to take place of looping.

What's more, once a variable is assigned a value, the value of the variable can't be change in the future.
This is because Haskell is pure and has no side effects, you can't change the value of a variable during the process.

Above is some thinking about Haskell. In the next few days, I will write some basic knowledge and some tricks about Haskell and  introduce the stuff I've used when I was developing the Baccrat.

Night.
(Mark: if anyone who is confused what is side-effect in programming, the following link is its defination coming from wiki
http://en.wikipedia.org/wiki/Side_effect_(computer_science)
)

没有评论:

发表评论