Skip to content

Instantly share code, notes, and snippets.

@evancz
evancz / Workflow.elm
Last active January 4, 2016 09:29
How one might implement a Workflow (Monad) library in some future version of Elm.
module Workflow where
import List
import Maybe as M
import Either as E
type Workflow container =
{ return : forall a. a -> container a
, bind : forall a. container a -> (a -> container b) -> container b
}
@evancz
evancz / Ports.js
Last active March 21, 2019 17:37
Example usage of Elm "ports" that uses signals, non-signals, records, and tuples. Build the Elm code with "elm --only-js Shanghai.elm" and include all of the JS in the HTML document.
// initialize the Shanghai component which keeps track of
// shipping data in and out of the Port of Shanghai.
var shanghai = Elm.worker(Elm.Shanghai, {
coordinates:[0,0],
incomingShip: { name:"", capacity:0 },
outgoingShip: ""
});
function logger(x) { console.log(x) }
@evancz
evancz / Main.html
Last active October 22, 2020 10:46
Embed an Elm module in HTML. Compile with `elm-make Stamper.elm` or just generate the HTML automatically by specifying an HTML output file with `elm-make Stamper.elm --output=Main.html`
<html>
<head>
<title>Embedding Elm in HTML!</title>
<script type="text/javascript" src="elm.js"></script>
</head>
<body>
<h1>Stamper</h1>
<div id="stamper" style="width:50%; height:400px;"></div>
@evancz
evancz / NameEntry.elm
Created October 25, 2013 15:41
Examples of markdown interpolation in Elm's markdown branch: https://github.com/evancz/Elm/tree/markdown
import Graphics.Input as Input
import String
main = lift2 scene textBox name
(textBox, name) = Input.field "What is your name?"
scene textBox name = [markdown|
{{ textBox }}
@evancz
evancz / Evaluator.hs
Last active December 25, 2015 02:59
How to evaluate a simple lambda calculus with a call-by-value semantics: http://www.seas.harvard.edu/courses/cs152/2013sp/lectures/lec07.pdf
data Expr
= Literal Int
| Lambda String Expr
| Apply Expr Expr
| Var String
| Sum Expr Expr
deriving Show
eval :: Expr -> Expr
eval expr =
module IntSet (empty,singleton,insert) where
data IntSet = Empty | Node Int IntSet IntSet
empty : IntSet
empty = Empty
singleton : Int -> IntSet
singleton x = Node x Empty Empty
@evancz
evancz / Mario.elm
Last active December 17, 2015 08:39
Embedding an Elm module in HTML. Warning, this is using a pre-release version of Elm 0.8, so the API may change!!!
module Mario where
import Keyboard
import Mouse
import Window
-- MODEL
mario = { x=0, y=0, vx=0, vy=0, dir="right" }