What is Haskell?
When you are starting out in Haskell, you need keep these items in your mind:
- Purely function programming language:
f(x) => g
, if it is called twice with the same parameters x, it is guaranteed to return the same result g - Lazy
- Statically Typed: It means
type inference
, you don’t explicitly state their type.
Run ghc’s interactive mode to Get a very basic feel for Haskell
Operators
simple arithmetic
+
,-
,*
,/
; if we want to have a negative number, it’s always best to surround it with parentheses. like5 * (- 3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19$ ghci
GHCi, version 6.8.2: http://www.haskell.org/ghc/ :? for help
Loading package base ... linking ... done.
prelude>
# +-*/
$ ghci> 2 + 15
17
$ ghci> 49 * 100
4900
$ ghci> 5 / 2
2.5
$ ghci> 50 * 100 - 4999
1
# use parentheses to change it
$ ghci> 50 * (100 - 4999)
-244950
$ ghci> 5 * - 3 # ❌
$ ghci> 5 * (- 3) # ✅
-15Boolean algebra: True, False,
&&
,||
,not
equality:
==
,/=
. what about doing5 + "llama"
or5 == True
? we will get a big error message! Don’t do that!1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21$ ghci> True && False
False
$ ghci> True && True
True
$ ghci> False || True
True
$ ghci> not False
True
$ ghci> not (True && True)
False
$ ghci> 5 == 5
True
$ ghci> 1 == 0
False
$ ghci> 5 /= 5
False
$ ghci> 5 /= 4
True
# but we can do 5 + 4.0
$ ghci> 5 + 4.0 # 5 can act like an integer or a floating-point number.
9.0
function: prefix, infix
prefix function
prefix function
like succ function
takes anything that has a defined successor and return that successor. it means it can increase the parameter(like numbers).
also, The functions min
and max
take two things that can be put in an order(like numbers).
1 | ghci> succ 8 |
infix function
backticks: `
1 | # division |