Skip to content

Instantly share code, notes, and snippets.

View TheSeamau5's full-sized avatar

Hassan Hayat TheSeamau5

  • Entrepreneur
  • Austin, TX
View GitHub Profile
@TheSeamau5
TheSeamau5 / QuasiFullECS.elm
Last active August 3, 2017 23:09
Quasi-Full expression of Entity Component System in Elm
import Color (Color, rgb)
import Graphics.Collage (..)
import Graphics.Element (Element)
import List ((::), map)
import Signal (Signal, foldp, (<~), sampleOn)
import Keyboard (arrows)
import Time (millisecond, every)
--------------------------
@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 / VisualBinaryTree.elm
Last active September 19, 2015 19:05
Visual representation of binary trees in Elm
import Text (asText)
import Graphics.Collage (collage, toForm, filled, circle, move, scale, Form)
import Graphics.Element (Element)
import Color (red)
import List (map, (::), reverse)
type BinaryTree a = Nil | Node (BinaryTree a) a (BinaryTree a)
insert : comparable -> BinaryTree comparable -> BinaryTree comparable
insert node tree =
@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 / makingElmDynamicSafely.md
Last active February 16, 2017 20:40
Proposal to make Elm more dynamic while maintaining type safety

Making Elm more Dynamic safely

The goal of this piece is to explore ways to give Elm some of the awesome features of dynamic languages while not sacrificing Elm's safety. The following ideas have come from exploring entity component systems/plugin architectures and noticing some of Elm's "limitations" to represent some of these ideas.

*NOTE: I am by no means an expert in type systems, compiler, programming languages, or actually programming in general. These are simply ideas I have been playing around with in recent weeks and wished to share with the Elm community. The hope is not that my ideas be adopted or pushed for or whatever. The goal is simply to improve the Elm language/platform by exploring possibilities to enhance the language in such a way as to not break any of its current guarantees or void any of its current advantages. The following is an exploration on how to make Elm's type system more "dynamic" in the sense that the inputs may be of unknown type while keeping the static nature of the lan

@TheSeamau5
TheSeamau5 / hackyECS.elm
Last active October 7, 2015 15:53
Entity Component Systems in Elm using hacks à-la elm-webgl
type Entity entity = Entity
type Component = Component
get : String -> Entity -> Maybe Component
get = ECS.Native.get
update : String -> a -> Entity -> Entity
update = ECS.Native.update