first commit

This commit is contained in:
Yehowshua Immanuel 2025-02-12 15:54:12 -05:00
commit 13c1ed7b2a
35 changed files with 3330 additions and 0 deletions

38
content/chapter4/page3.md Normal file
View file

@ -0,0 +1,38 @@
+++
title = "`type`"
weight = 1
+++
Defines a type synonym. These are used purely for readability, *i.e.,* a
type synonym can always be "expanded out" to its definition at any time.
```
topDefn ::= type typeId {tyVarId }= type
```
Examples:
```hs
type Byte = Bit 8
type Word = Bit 16
type LongWord = Bit 32
```
These provide commonly used names for certain bit lengths. In a
specification of a processor:
```hs
data RegName = R0 | R1 | ... | R31
type Rdest = RegName
type Rsrc = RegName
data ArithInstr = Add Rdest Rsrc Rsrc
| Sub Rdest Rsrc Rsrc
```
the last two lines suggest the roles of the registers in the
instructions, and is more readable than:
```hs
data ArithInstr = Add RegName RegName RegName
| Sub RegName RegName RegName
```