evincarofautumn / evincarofautumn/hap-hs

Type and object system

Open
#2 2 comments 0 reactions 0 assignees View on GitHub
Dominant language
Haskell
Stars
12
Forks
2
PR merge metrics
No merged PRs in 30d

Description

I think program organisation will not scale well to larger sizes without some form of type checking. I think some subset of the following features make sense:

* A *fixed* set of *intrinsic*, principal, inferable types:
* Dynamic
* Primitive
* Void (“empty”)
* Unit (“dummy”)
* Boolean
* Numeric
* Integers
* Rationals
* Floats
* Text (text only, no “character” type; any functions operating on code points use integers)
* Containers
* Arrays
* Maps
* Sets
* Connectives
* Functions
* Polymorphic types
* Tuples
* Sums
* Game primitives
* Images
* Sounds
* Inputs

* An *extensible* set of *extrinsic* types (“properties”) that are not necessarily principal, inferable, or statically checkable, which refine intrinsic types:
* Records (maps with particular keys, mapping to values of particular types)
* Intersections (“and”)
* Unions (“or”)
* Top (“any”)
* Bottom (“none”)

While every *value* should have an intrinsic type, it should be possible to give *variables* a dynamic type. For dynamically typed values, it should be possible to check or assert that they have the correct type, providing static type information to the type checker.

Typechecking the program should produce *warnings* about type errors without preventing the program from running. A type mismatch at runtime should produce an error and pause the program for debugging. In strict mode, these warnings can be turned into errors.

It should be possible to define *objects* (“entities”), as a form of property that provides some combination of fields, commands, and queries. I would like entities to *declare* the fields they expect or provide, with optional defaults; define *methods* for commands and queries and *events* for how they update, render, or respond to input; and be automatically *linked* together. Sketch:

```
entity Position {
has x: int;
has y: int;
}

entity Velocity {
has vx: int = 0;
has vy: int = 0;
needs x: int;
needs y: int;
whenever (updating) {
x += vx * dt;
y += vy * dt;
}
}

entity Sprite {
has frame: int = 0;
needs image: Image? = null;
needs x: int;
needs y: int;
whenever (rendering) {
graphics_draw_image(self.image, self.x, self.y);
}
}

entity ArrowKeyVelocityControls {
needs velocity: Velocity;
whenever (key_down <> null) {
if (key_down = LEFT_ARROW) { self.velocity.vx = -1; }
// …
}
}

entity Player {
has image: Image;
has sprite: Sprite;
has position: Position;
has controls: ArrowKeyVelocityControls;
}

var player = new Player {
image: player_sprite,
position.x: screen_width / 2,
position.y: screen_height / 2
};
```

Contributor guide

No contributing guide indexed for this repository

Research direction

The issue names no files, tests, or entry points to inspect. Before implementation, define a smaller agreed scope; completion would require the selected type and object features, warning and runtime-error behavior, strict mode, and tests to be specified.

Written by the indexing model from the issue text.

Assessment

Tech stack
haskell
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
20/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.