Skip to content

Instantly share code, notes, and snippets.

View TheSeamau5's full-sized avatar

Hassan Hayat TheSeamau5

  • Entrepreneur
  • Austin, TX
View GitHub Profile
type alias Entity = {
position : Vector,
velocity : Vector,
scale : Vector,
...
}
type alias World = List Entity
type alias ComponentCreator = Entity -> Entity
@TheSeamau5
TheSeamau5 / gridMapWithIndices.elm
Last active August 29, 2015 14:12
Function to map a function over a grid while passing in the indices
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
@TheSeamau5
TheSeamau5 / BinaryTree.elm
Created January 5, 2015 15:15
Binary Tree in Elm
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
@TheSeamau5
TheSeamau5 / metaAnnotations.elm
Last active August 29, 2015 14:12
Proposal for meta annotations in Elm
-- 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 }
@TheSeamau5
TheSeamau5 / symbols.elm
Created January 6, 2015 16:22
Proposal for Symbols in Elm.
-- 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
@TheSeamau5
TheSeamau5 / heterogeneousLists.elm
Created January 6, 2015 16:39
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 = {
@TheSeamau5
TheSeamau5 / usingHeterogeneousLists.elm
Created January 6, 2015 17:21
Using Heterogeneous lists in Proposal in Elm
mario = {
position = {x = 0, y = 0},
velocity = {x = 0, y = 0},
mass = 10,
Life,
Groundedness,
Controllability
}
goomba = {
@TheSeamau5
TheSeamau5 / ECSExampleInDartOOPStyle.dart
Created January 7, 2015 22:24
ECS Example in Dart using OOP
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);
}
@TheSeamau5
TheSeamau5 / Pong3D.elm
Last active August 29, 2015 14:13
Pong in 3d using Graphics Engine in Elm
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
@TheSeamau5
TheSeamau5 / Loops.elm
Created January 24, 2015 23:43
A neat construct to loop in Elm without worrying about stack problems
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)