Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

chore: fix typos in associated-effects.md #155

Merged
merged 1 commit into from
May 15, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 9 additions & 9 deletions src/associated-effects.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,19 +10,19 @@ We can define a trait for types that can be divded:

```flix
trait Dividable[t] {
pub def add(x: t, y: t): t
pub def div(x: t, y: t): t
}
```

and we can implement the trait for e.g. `Float32` and `Int32`:

```flix
instance Dividable[Float32] {
pub def add(x: Float32, y: Float32): Float32 = x / y
pub def div(x: Float32, y: Float32): Float32 = x / y
}

instance Dividable[Int32] {
pub def add(x: Int32, y: Int32): Int32 = x / y
pub def div(x: Int32, y: Int32): Int32 = x / y
}
```

Expand All @@ -35,7 +35,7 @@ pub eff DivByZero {
}

instance Dividable[Int32] {
pub def add(x: Int32, y: Int32): Int32 \ DivByZero =
pub def div(x: Int32, y: Int32): Int32 \ DivByZero =
if (y == 0) do DivByZero.throw() else x / y
}
````
Expand All @@ -45,9 +45,9 @@ But unfortunately this does not quite work:
```
❌ -- Type Error --------------------------------------------------

>> Mismatched signature 'add' required by 'Dividable'.
>> Mismatched signature 'div' required by 'Dividable'.

14 | pub def add(x: Int32, y: Int32): Int32 \ DivByZero =
14 | pub def div(x: Int32, y: Int32): Int32 \ DivByZero =
^^^
...
```
Expand All @@ -65,7 +65,7 @@ specify that a `DivByZero` exception may be raised whereas the instance for
```flix
trait Dividable[t] {
type Aef: Eff
pub def add(x: t, y: t): t \ Dividable.Aef[t]
pub def div(x: t, y: t): t \ Dividable.Aef[t]
}
```

Expand All @@ -74,12 +74,12 @@ and we re-implement the instances for `Float32` and `Int32`:
```flix
instance Dividable[Float32] {
type Aef = { Pure } // No exception, div-by-zero yields NaN.
pub def add(x: Float32, y: Float32): Float32 = x / y
pub def div(x: Float32, y: Float32): Float32 = x / y
}

instance Dividable[Int32] {
type Aef = { DivByZero }
pub def add(x: Int32, y: Int32): Int32 \ DivByZero =
pub def div(x: Int32, y: Int32): Int32 \ DivByZero =
if (y == 0) do DivByZero.throw() else x / y
}
```
Expand Down
Loading