---
# System prepended metadata

title: Haskell

---

# Haskell


## Misc

### Syntax
```=hs
func x = if [state]
           then []
           else []
func x = if [state] then [] else []
```

### List
add
```
[list1] ++ [list2]
element : [list]
```
get element by index
```
list !! index
```
functions
```
head l: l[0]
tail l: l[1:]
last l: l[-1]
init l: l[:-1]

length
null l: checks if l is empty
reverse
take a: [:a]
drop a: [a:]
maximum
minimum
sum
product
elem a list: if a in list

cycle l: infinite list of repeat l
repeat a: infinite list of a
replicate a b: list of element b of a times
```
range
```
[1..3] = [1,2,3]
['a'..'c'] = ['a','b','c']
```
list comprehension
```
example:
[x | x <- [1..3]]
[x | x <- [1..3], x > 2]
[if x > 0 then "yee" else "nah" | x <- xs, odd x]
[x * y | x <- [1..3], y <- [4..6]]
```
zip
### Operator
```
/=
```

### Infix function
```
func arg1 arg2
arg1 `func` arg2
```