Skip to content

Instantly share code, notes, and snippets.

View johnpmayer's full-sized avatar

John P Mayer, Jr johnpmayer

View GitHub Profile
@johnpmayer
johnpmayer / main.rs
Last active August 29, 2015 14:05
Dining Philosophers - Can't seem to make it deadlock
extern crate sync;
use sync::Arc;
use sync::Mutex;
static N : uint = 5;
fn philosopher(seat : uint, vec : &Arc<Vec<Mutex<()>>>) {
let leftFork = seat;
let rightFork = (seat + 1) % N;
println!("Philosopher {} {} {}", seat, leftFork, rightFork);
@johnpmayer
johnpmayer / LL.hs
Created March 22, 2013 19:30
This is an implementation of a Linked List in the STM monad!
{-# OPTIONS -Wall #-}
module LL (empty, append, index, delete) where
import Control.Concurrent.STM
data Node a = Node a (LinkedList a)
type LinkedList a = TVar (Maybe (Node a))
@johnpmayer
johnpmayer / gist:5250857
Created March 27, 2013 01:34
Storable Byte-sized TypeReps for natural numbers using existentials
{-# OPTIONS -Wall #-}
{-# LANGUAGE GADTs, DataKinds, KindSignatures, RankNTypes,
FlexibleInstances, PolyKinds, ScopedTypeVariables #-}
module Utils where
import Data.Int
import Foreign.Ptr
import Foreign.Storable
@johnpmayer
johnpmayer / gist:5271503
Last active December 15, 2015 13:59
Algebraic Effects in Haskell
{-# OPTIONS -Wall #-}
{-# LANGUAGE GADTs, DataKinds, TemplateHaskell, KindSignatures,
MultiParamTypeClasses, RankNTypes, PolyKinds, FlexibleContexts,
TypeFamilies, UndecidableInstances, FlexibleInstances #-}
module Effects where
import Data.Singletons
@johnpmayer
johnpmayer / Bar.elm
Created April 22, 2013 03:25
Demo of how I'd like to be able to import type aliases
module Bar where
type A = { x : Int, y : Int }
@johnpmayer
johnpmayer / gist:5448143
Last active December 16, 2015 14:20
Use case of loop (I did not try to compile this code)
{-
- This is the loop function that I propose as an ehancement.
- I think it's better because the asychonous loopback signal
- is anonymous, rather than a top-level definition.
-}
loop : (b -> a) -> b -> (Signal a -> Signal b) -> Signal b
-- Here's how we're going to control our little demo
powerButton : Element
power : Signal Bool
@johnpmayer
johnpmayer / Loop.js
Last active December 16, 2015 16:39
A shot at an unsafe loop construct Native Elm library. Not necessarily intended to be part of the standard library.
Mayer.John.Native.Loop = function(elm) {
// Various boilerplate stuff
'use strict';
if (elm.Native.Loop) return elm.Native.Loop;
var Signal = Elm.Signal(elm);
// This is the unsafe loop construct
// loop : (b -> a) -> (Signal a -> Signal b) -> b -> Signal b
var loop = function(convert, transform, initial) {
@johnpmayer
johnpmayer / Loop.elm
Created June 9, 2013 21:50
Using the new foldp-like loop function
module Loop where
import Graphics.Input (checkbox)
-- compiler note, impossible to put a valid type signature here
-- check : Signal Element
-- power : Signal Bool
(check, power) = checkbox true
tick : Signal Time
@johnpmayer
johnpmayer / console
Last active December 20, 2015 17:39
Another vector library in Elm, which fails due to a suspected bug in the record type system?
[1 of 5] Compiling Vec2 ( Vec2.elm )
Type error on line 31:
{x = v.x, y = v.y}
Expected Type: a
Actual Type: {}
Type error on line 34:
# Assumes the following are available
#
# jq
curl https://api.github.com/users/johnpmayer/keys