# Singleton

## Purpose

Sometimes, when we are creating libraries for other users, we might want to group similar functions together to improve user experience.

## Example

Suppose we are creating a library that allow the user to access the file system. And we wish that our code looks like this:

```c
=fs.open("Hello world.txt")
```

First, we need to create a [tagged union](https://github.com/KeliLanguage/doc/tree/ca3560b83f8cf54d525372371bc36c4050690398/features-1/tagged-unions.md) with only a single tag:

```c
FileSystem = choice.new
```

Then, create a constant alias:

```c
fs = FileSystem.new
```

After that, we can proceed to define the functions we intend to expose:

```c
(this FileSystem).open(filename String) = undefined
(this FileSystem).rename(oldname String) as(newname String) = undefined
(this FileSystem).delete(filename String) = undefined
```

And the client can use them as follows:

```c
=fs.open("Hello world.txt")
=fs.rename("Jojo.md") as("Koko.md")
=fs.delete("/")
```


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://keli-language.gitbook.io/doc/techniques/singleton.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
