This file contains 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
type alias Entity = { | |
position : Vector, | |
velocity : Vector, | |
scale : Vector, | |
... | |
} | |
type alias World = List Entity | |
type alias ComponentCreator = Entity -> Entity |
This file contains 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
gridMapWithIndices : (Int -> Int -> a -> b) -> List (List a) -> List (List b) | |
gridMapWithIndices function grid = | |
let iterateColumns x y columnCount row = | |
if (x >= columnCount || row == []) then [] | |
else | |
function x y (head row) :: iterateColumns (x + 1) y columnCount (tail row) | |
iterateRows y rowCount grd = | |
if (y >= rowCount) then [] | |
else |
This file contains 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
type BinaryTree a = Nil | Node (BinaryTree a) a (BinaryTree a) | |
insert : comparable -> BinaryTree comparable -> BinaryTree comparable | |
insert node tree = | |
case tree of | |
Nil -> Node Nil node Nil | |
Node left leaf right -> | |
if | leaf == node -> Node left leaf right | |
| leaf < node -> Node left leaf (insert node right) | |
| leaf > node -> Node (insert node left) leaf right |
This file contains 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
-- REQUIRE META ANNOTATION: | |
-- The require meta-annotation will force the input record type vector to have a z field | |
require {z : Float} from vector | |
moveZ : Float -> vector -> vector | |
moveZ z v = { v | z <- v.z + z } | |
-- The top code is equivalent to | |
moveZ : Float -> { a | z : Float } -> { a | z : Float } | |
moveZ z v = { v | z <- v.z + z } |
This file contains 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
-- life is a singleton. it acts as a symbol | |
-- In this case, we use the presence or absence of this symbol as a boolean flag. | |
mario = { | |
position = { | |
x = 0, | |
y = 0 | |
}, | |
velocity = { | |
x = 0, | |
y = 0 |
This file contains 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 = { |
This file contains 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
mario = { | |
position = {x = 0, y = 0}, | |
velocity = {x = 0, y = 0}, | |
mass = 10, | |
Life, | |
Groundedness, | |
Controllability | |
} | |
goomba = { |
This file contains 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
class Point { | |
final num x; | |
final num y; | |
const Point(this.x, this.y); | |
Point operator + (Point p) { | |
return new Point(p.x + x, p.y + y); | |
} | |
Point scale(num factor){ | |
return new Point(x * factor, y * factor); | |
} |
This file contains 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
import Engine (..) | |
import Engine.Material.Material (MaterialProperty) | |
import Math.Vector3 (vec3, Vec3) | |
import Engine.Shader.GouraudShader (gouraudShader) | |
import Time (..) | |
import Signal (..) | |
import Keyboard | |
import Window |
This file contains 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
loop : a -> (a -> Bool) -> (a -> a) -> (a -> b) -> b | |
loop start condition update return = | |
trampoline <| | |
loop' start condition update return | |
loop' : a -> (a -> Bool) -> (a -> a) -> (a -> b) -> Trampoline b | |
loop' start condition update return = | |
case condition start of | |
True -> Done (return start) |