<commit_before>---
published: true
title: String Operators
layout: post
tags: [haskell, strings]
---
In Haskell, strings are lists of characters (their type is [Char]). There are a few operators useful to manipulate strings:

### : or cons
: can be used to add an element to a list.
```haskell
> 'a' : "bcd"
"abcd"
```

### head
Head returns the first element in a list.
```haskell
> head "Hello World"
"H"
```

### tail
Tail returns the rest of a list after the head
```haskell
> tail "Hello World"
"ello World"
```

### take
Take returns the first x items of a list
```haskell
> take 5 "Hello World"
"Hello"
```

### drop
Drop removes the first x elements from a list and returns the remainder
```haskell
> drop 5 "Hello World"
" World"
```

### !!
!! returns the element at the specified index in the list
```haskell
> "Hello World" !! 5
" "
```

### ++
++ is used to concatenate, or join together, lists.
```haskell
> "Hello " ++ "World"
"Hello World"
```<commit_msg>Post update: String Operators<commit_after>---
published: true
title: String Operators
layout: post
tags: [haskell, strings]
---
In Haskell, strings are lists of characters (their type is [Char]). There are a few operators useful to manipulate strings:

### : or cons
: can be used to add an element to a list.
```
> 'a' : "bcd"
"abcd"
```

### head
Head returns the first element in a list.
```
> head "Hello World"
"H"
```

### tail
Tail returns the rest of a list after the head
```
> tail "Hello World"
"ello World"
```

### take
Take returns the first x items of a list
```
> take 5 "Hello World"
"Hello"
```

### drop
Drop removes the first x elements from a list and returns the remainder
```
> drop 5 "Hello World"
" World"
```

### !!
!! returns the element at the specified index in the list
```
> "Hello World" !! 5
" "
```

### ++
++ is used to concatenate, or join together, lists.
```
> "Hello " ++ "World"
"Hello World"
```
{'fraction_non_alphanumeric': 0.15243583027763227, 'fraction_numerical': 0.003143006809848088, 'mean_word_length': 3.922680412371134, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '7648700', 'n_tokens_mistral': 655, 'n_tokens_neox': 599, 'n_words': 278}