mirror of
https://github.com/erg-lang/erg.git
synced 2025-09-28 20:14:45 +00:00
59 lines
1.6 KiB
Markdown
59 lines
1.6 KiB
Markdown
# alstruct
|
|
|
|
[](https://gezf7g7pd5.execute-api.ap-northeast-1.amazonaws.com/default/source_up_to_date?owner=erg-lang&repos=erg&ref=main&path=doc/EN/API/modules/external/alstruct.md&commit_hash=14657486719a134f494e107774ac8f9d5a63f083)
|
|
|
|
代数的構造を表すトレイトや、それにかかるパッチを提供するモジュール。
|
|
|
|
* member
|
|
|
|
## BinOp
|
|
|
|
```python
|
|
BinOp Op: Kind 2 = Subsume Op(Self, Self.ReturnTypeOf Op), Additional: {
|
|
.ReturnTypeof = TraitType -> Type
|
|
}
|
|
|
|
Nat <: BinOp Add
|
|
assert Nat.ReturnTypeof(Add) == Nat
|
|
assert Nat.ReturnTypeof(Sub) == Int
|
|
assert Nat.ReturnTypeof(Mul) == Nat
|
|
assert Nat.ReturnTypeof(Div) == Positive Ratio
|
|
```
|
|
|
|
## SemiGroup
|
|
|
|
```python
|
|
SemiGroup Op: Kind 2 = Op(Self, Self)
|
|
|
|
IntIsSemiGroupAdd = Patch Int, Impl := SemiGroup Add
|
|
|
|
Int <: SemiGroup Add
|
|
```
|
|
|
|
## Functor
|
|
|
|
```python
|
|
## * Identity law: x.map(id) == x
|
|
## * Composition law: x.map(f).map(g) == x.map(f.then g)
|
|
Functor = Trait {
|
|
.map|T, U: Type| = (Self(T), T -> U) -> Self U
|
|
}
|
|
```
|
|
|
|
## Applicative
|
|
|
|
```python
|
|
## * Identity law: x.app(X.pure(id)) == x
|
|
Applicative = Subsume Functor, Additional: {
|
|
.pure|T: Type| = T -> Self T
|
|
.app|T, U: Type| = (Self(T), Self(T -> U)) -> Self U
|
|
}
|
|
```
|
|
|
|
## Monad
|
|
|
|
```python
|
|
Monad = Subsume Applicative, Additional: {
|
|
.bind|T, U: Type| = (Self(T), T -> Self U) -> Self U
|
|
}
|
|
```
|