Skip to content

Instantly share code, notes, and snippets.

module Animal where
data Either a b = Left a | Right b
-- Left 42 <=> { "tag":"Left", "contents":[42] }
-- Right "cat" <=> { "tag":"Right", "contents":["cat"] }
port animal : Signal (Either Int String)
port animal = always (Right "cat") <~ every second
import Char (isDigit)
import String (all)
import Graphics.Input (Input, input, FieldContent, noContent, field)
main : Signal Element
main = scene <~ content.signal
content : Input FieldContent
content = input noContent
@evancz
evancz / Checks.elm
Created February 27, 2014 16:11
A bunch of synced check boxes
import Graphics.Input as Input
main : Signal Element
main = lift display check.signal
check : Input.Input Bool
check = Input.input True
display : Bool -> Element
display checked =
type Point3D = { x : Float, y : Float, z : Maybe Float }
deriving Json, New, Binary
-- Resulting in the folliwing derived values:
Point3D.Json.encode : Point3D -> String
Point3D.Json.decode : String -> Maybe Point3D
Point3D.New : Float -> Float -> Maybe Float -> Point3D
@evancz
evancz / History.elm
Created April 23, 2014 19:39
General purpose library for undo/redo. Inspired by David Nolen's talk at Philly ETE.
module History where
data Step a = Undo | Redo | Checkpoint a | NoCheckpoint a
foldp : (a -> b -> b) -> b -> Signal (Step a) -> Signal b
-- It could also be interesting to have custom strategies for keeping track
-- of history. Maybe you want to have a fixed size stack, infinite stack,
-- stack with exponential decay, etc.
@evancz
evancz / Triangle.elm
Created May 15, 2014 02:08
A triangle that rotates, but done in a slow way. Ideally you send a transformation matrix to the GPU rather than a whole new entity!
import Math.Vector3 (..)
import Math.Matrix4 (..)
import Graphics.WebGL (..)
-- This is the main function
-- It renders the triangle then prints the points
-- of the triangle
-- Notice how the points change but the render doesn't
main = flow down <~ ( combine [ render <~ updateTriangle
@evancz
evancz / ThwompBlinks.elm
Created May 20, 2014 22:35
Thwomp program, except Thwomp blinks periodically
@evancz
evancz / Command Line Refresh.md
Last active August 29, 2015 14:04
A proposal for how to make all of the command line tools nicer.

Command Line Refresh for Elm

With the upcoming improvements to elm-server and elm-get, it is becoming clear that the names of the various command line tools do not actually match what they do. This is a proposal of how to sort this out.

Proposal

I propose that the typical workflow will include the following tools:

  • elm-repl - exactly the same as before
  • elm-reactor - combination of elm-server and the debugger
@evancz
evancz / hackathon_elm-html.md
Last active August 29, 2015 14:07
Some helpful guidance, links, and examples to make this hackathon more fun and productive.

Elm Hackathon 1

Theme: exploring and using elm-html

I want us to make some cool stuff together. First, I think it will be fun, but I think we may begin to learn interesting ways to improve and extend elm-html so that we can all be more productive.

@evancz
evancz / Floatify.elm
Created November 11, 2014 04:10
Trying out different ways to avoid toFloat conversions, based on this discussion (https://groups.google.com/forum/#!topic/elm-discuss/YPA2ww2P9PU)
import Window
import Color
floatify : (Int,Int) -> (Float,Float)
floatify (x,y) =
(toFloat x, toFloat y)
scene (w,h) =
flow down
[ container (floor w) (floor (h / 2)) middle (asText "blue")