Skip to content

Instantly share code, notes, and snippets.

@TheSeamau5
Created January 6, 2015 16:39
Show Gist options
  • Save TheSeamau5/f5006a078f4ec56dc058 to your computer and use it in GitHub Desktop.
Save TheSeamau5/f5006a078f4ec56dc058 to your computer and use it in GitHub Desktop.
Safe Heterogeneous Lists through meta-annotations
-- We could use meta-annotations to have heterogeneous lists
mario = {
position = { x = 0, y = 0 },
velocity = { x = 0, y = 0 },
Life,
Controllability,
Groundedness
}
goomba = {
position = { x = 0, y = 0 },
velocity = { x = 0, y = 0 },
Groundedness
}
lakituCloud = {
position = { x = 0, y = 100 },
velocity = { x = 0, y = 0 },
Flight,
Life
}
-- One way to have heterogeneous lists is to require a set number of fields
-- Anything else would be optional
require {position : {x : Float, y : Float}, velocity : {x : Float, y : Float}} from entity
entities : List entity
entities = [mario, goomba, lakituCloud]
-- Another way is to state all of the optional stuff
type alias Entity = {
position : {x : Float, y : Float},
velocity : {x : Float, y : Float}
}
optional {Life, Controllability, Groundedness, Flight} from Entity
entities2 : List Entity
entities2 = [mario, goomba, lakituCloud]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment