Update tech_docs/CUE_your_new_friend.md
This commit is contained in:
@@ -283,3 +283,38 @@ graph TD
|
||||
I["Example:\nname: string & =~'^[A-Z]'"] --> D
|
||||
J["Example:\nrole: 'admin' | 'user'"] --> G
|
||||
```
|
||||
|
||||
---
|
||||
|
||||
It looks like you're describing concepts related to type systems or constraint solving in programming languages. Let's break down each term and how they might be used in such a context:
|
||||
|
||||
### 1. Top (\(_\))
|
||||
- **Definition**: The "Top" value is a universal type or constraint that can accept any value. It represents the most general or unrestricted type.
|
||||
- **Example**: In a type system, the "Top" type might be something like `Any` or `Object`, which can hold any kind of value (e.g., strings, integers, objects, etc.).
|
||||
|
||||
### 2. Bottom (\(_|\_\))
|
||||
- **Definition**: The "Bottom" value represents an invalid or conflicting state. It is often used to indicate an error or an impossible condition.
|
||||
- **Example**: In a type system, the "Bottom" type might be something like `Never` or `Void`, which represents a type that can never be instantiated. It is used to signal errors or contradictions.
|
||||
|
||||
### 3. Unification (\(&\))
|
||||
- **Definition**: Unification combines constraints in a way that is similar to a logical AND. It finds the most specific type or constraint that satisfies all given constraints.
|
||||
- **Example**: If you have two constraints \(A\) and \(B\), \(A \& B\) will result in a new constraint that is the intersection of \(A\) and \(B\). For example, if \(A\) is `int` and \(B\) is `number`, \(A \& B\) might result in `int` because `int` is a more specific type of `number`.
|
||||
|
||||
### 4. Disjunction (\(|\))
|
||||
- **Definition**: Disjunction allows alternatives, similar to a logical OR. It represents a type or constraint that can be one of several possible values.
|
||||
- **Example**: If you have two constraints \(A\) and \(B\), \(A | B\) will result in a new constraint that can be either \(A\) or \(B\). For example, if \(A\) is `int` and \(B\) is `string`, \(A | B\) represents a type that can be either an `int` or a `string`.
|
||||
|
||||
### Example in Practice
|
||||
Let's consider a simple example in a hypothetical type system:
|
||||
|
||||
```plaintext
|
||||
Type A = int
|
||||
Type B = string
|
||||
Type C = A & B
|
||||
Type D = A | B
|
||||
```
|
||||
|
||||
- **Type C**: Since `int` and `string` are incompatible types, \(A \& B\) would result in the "Bottom" type (\(_|\_\)), indicating an error or conflict.
|
||||
- **Type D**: \(A | B\) would result in a type that can be either `int` or `string`.
|
||||
|
||||
These concepts are fundamental in type inference and constraint solving in programming languages, particularly in statically typed languages like TypeScript, OCaml, or Haskell.
|
||||
Reference in New Issue
Block a user