Created
January 6, 2015 16:39
-
-
Save TheSeamau5/f5006a078f4ec56dc058 to your computer and use it in GitHub Desktop.
Safe Heterogeneous Lists through meta-annotations
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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