Sayfalar

25 Temmuz 2014 Cuma

Haskell Day2


Learning Haskell Day2

         Today I learned about truth values and basic types. Truth values similar to other high-level programming languages. There are two variables such as “True” and “False”. If a condition is not right it will be false otherwise true. For example this program print False

sq x = x * x
main=print(sq 2 ==5 )

Or this one will return true

vol x y z = x*y*z
main=print(vol 3 4 5 == 60).

Of course we can do some boolean operation like “and” and “or”.For and we use && and if one of the condition is false it will be false.For or we use || it is enough to being true if one of them is true.For example:

main=do
      print(3==3 && 4==2)
      print(3==3 || 4==2)
      print((==) 3 5 )

the output like
false true false

first two line is seems normal but third condition is different. The == operator can bu used like a prefix operator even it take two arguments.

Types in Haskell very similar to other programming languages char strings... . If you want to learn a type of a variables on ghci you can use :type ot :t for example :t True will be return boolean.

Hiç yorum yok:

Yorum Gönder