Skip to content

Commit

Permalink
wu12: Cleanup formatting and add question answer
Browse files Browse the repository at this point in the history
  • Loading branch information
CohenArthur committed Oct 6, 2023
1 parent 2151dd9 commit fcf582e
Showing 1 changed file with 32 additions and 31 deletions.
63 changes: 32 additions & 31 deletions docs/writeups/0012-default-field-access.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,24 @@ The `source` function exposed in WU0009 is more likely to return a new type than
Introduce a new operator `::` to access a type's default field value

```rust
type List = source("list");
type list = source("list");

where l = List.map([1, 2, 3], x -> x * 2);
where l = list.map([1, 2, 3], x -> x * 2);
```

In the above example, `List` is not an instance of the type `List` - it is the actual List *type*. You can imagine that it contains the following fields:

```rust
type List(
map: func[T, U](Array[T], func(T) -> U) -> Array[U] = /* default map function */
type list(
map: func[T, U](Array[T], func(T) -> U) -> Array[U] = /* default map */
);
```

Hence, accessing the `map` field requires an instance of type `List` - so we must first create one:

```rust
type List = source("list");
where list = List;
type list = source("list");
where list = list;

where l = list.map([1, 2, 3], x -> x * 2);
```
Expand All @@ -40,20 +40,11 @@ Adding an `::` operator to *explicitly* indicate that we would like to use a typ
## Examples

```rust
type List = source("list");

where l = List::map([1, 2, 3], x -> x * 2);
```

```rust
type Foo = source("foo");
// has module `Bar`, which has module `Baz`, which has type `Qux`
type list = source("list");

where q = Foo::Bar::Baz::Qux(x: 15, y: 14);
where l = list::map([1, 2, 3], x -> x * 2);
```

or

```rust
type foo = source("foo");
// has module `bar`, which has module `baz`, which has type `Qux`
Expand All @@ -69,18 +60,29 @@ func foo_pair(p: std::pair::Pair[int, string]) -> int { p.fst }

1. How to deal with module overriding?

2. module override instances vs default type accesses
```rust
type list = source("list");
where list_custom = List(
map: our_map,
);

3. syntax complexity
list::map([1, 2, 3], x -> x * 2)

4. "method" resolution
// these call `our_map`
list_custom::map([1, 2, 3], x -> x * 2) // works?
list_custom.map([1, 2, 3], x -> x * 2) // works for sure, but not consistent?

5. Multiline chaining allowed?
func our_map[T, U](l: Array[T], f: func(T) -> U) -> Array[U] { /* ... */ }
```

6. Prefered syntax for modules - lowercaps module names?
-> should the operator be a `field access or default access operator`?

2. module override instances vs default type accesses
3. syntax complexity
4. "method" resolution
5. Multiline chaining allowed?
6. Prefered syntax for modules - lowercaps module names?
7. How does it interact with types in general?

8. Other operators?

```rust
Expand All @@ -105,7 +107,7 @@ type list = source("list");
// becomes

type list(
map: func[T, U](Array[T], func(T) -> U) -> Array[U] = /* default map function */)
map: func[T, U](Array[T], func(T) -> U) -> Array[U] = /* default map */)
);

// binding with default initialization for all fields of the type `list`
Expand All @@ -114,19 +116,18 @@ where list = list();

```rust
func source(path: string) -> type {
type new_type = source_inner(path);
where receiver = jinko.magic.receiver_expr();
type new_type = source_inner(path);
where receiver = jinko.magic.receiver_expr();

receiver.scope().insert(
jinko.magic.binding(receiver.name(), new_type())
);
receiver.scope().insert(
jinko.magic.binding(receiver.name(), new_type())
);

new_type
new_type
}
```

## Issues

1. Very magic

2. Not great for compilation

0 comments on commit fcf582e

Please sign in to comment.