Skip to content

Types Reference

Relanote uses static typing with Hindley-Milner type inference.

Primitive Types

TypeDescriptionExample
UnitNo value()
BoolBooleantrue, false
IntInteger42
FloatFloating point3.14
StringText"hello"

Music Types

TypeDescriptionExample
IntervalMusical intervalP5, M3, m7
ScaleCollection of intervalsscale { R, M2, M3... }
ChordSimultaneous intervalschord [ R, M3, P5 ]
BlockSequence of notes| <1> <2> <3> |
PartInstrument trackpart "Piano" [...]
SectionSong sectionsection "Verse" ...
SongComplete compositionrender ...

Synth Types

TypeDescriptionExample
SynthSynthesizer definitionsynth Lead = {...}
OscillatorWaveform typeSine, Square, Saw
FilterFilter typeLowPass(1000, 0.5)
EnvelopeADSR envelope{ A: 0.01, D: 0.1, S: 0.7, R: 0.2 }

Compound Types

Arrays

rela
[1, 2, 3]           ; [Int]
["a", "b", "c"]     ; [String]
[R, M3, P5]         ; [Interval]

Functions

rela
Int -> Int              ; Function from Int to Int
(Int, Int) -> Int       ; Function with two Int parameters
Block -> Block          ; Block transformation

Tuples

rela
(Int, String)           ; Pair of Int and String
(Interval, Interval)    ; Pair of intervals

Type Inference

Types are inferred automatically:

rela
let x = 42              ; x: Int
let s = "hello"         ; s: String
let i = P5              ; i: Interval
let f = \n -> n + 1     ; f: Int -> Int

Type Annotations

Explicit annotations are optional but sometimes helpful:

rela
let x: Int = 42
let transpose: Interval -> Block -> Block = ...

Type Errors

The type checker catches errors at compile time:

rela
; Error: cannot add Scale to Interval
let wrong = Major + P5

; Error: type mismatch
let also_wrong: Int = "hello"

; Error: cannot apply Scale to Int
Major |> 42

Type Classes (Traits)

Some operations work on multiple types:

Eq (Equality)

rela
P5 == P5    ; true
M3 != m3    ; true

Add

rela
; Intervals can be added
P5 + M3     ; M7

; Blocks can be concatenated
| <1> | ++ | <2> |   ; | <1> <2> |

Show

All values can be displayed:

rela
; In the REPL or debug output
P5          ; "P5 (7 semitones)"
Major       ; "Scale { R, M2, M3, P4, P5, M6, M7 }"

Generic Functions

Some built-in functions are generic:

rela
; map works on any Block content
map: (a -> b) -> [a] -> [b]

; repeat works on any Block
repeat: Int -> Block -> Block

Released under the MIT License.