Skip to content

Instantly share code, notes, and snippets.

View jvranish's full-sized avatar

Job Vranish jvranish

  • Grand Rapids, MI
View GitHub Profile
@jvranish
jvranish / adt.rb
Created October 17, 2013 14:20
Simple algebraic datatypes for ruby
require 'stringio'
class ADT < Struct
def self.members() @members end
def self.add_member(c)
@members ||= []
@members << c
@members.length - 1
end
def self.data(*args)
@jvranish
jvranish / AST.hs
Created November 25, 2012 16:06
An example alternative AST construction using GADTs
class HasStmt a where
class HasDef a where
class HasExpr a where
data Module = Module [ParsedDef]
data ParsedDef = ParsedDef (Definition ParsedStmt) SourcePos
data ParsedStmt = ParsedStmt (Statement ParsedDef ParsedStmt ParsedExpr) SourcePos
data ParsedExpr = ParsedExpr (Expr ParsedExpr) SourcePos
@jvranish
jvranish / TypeDirected.hs
Created November 17, 2012 14:37
Example code for 1DevDay talk
{-#Language DeriveFunctor
, DeriveFoldable
, DeriveTraversable #-}
import Control.Applicative
import Data.Foldable
import Data.Traversable
import Prelude hiding (sum)
@jvranish
jvranish / Gemfile
Created August 12, 2012 01:53
An example explaining how to use bundler to replace externals/submodules
source "http://rubygems.org"
gem "my_awesome_lib", :path => "../my_awesome_lib"
# or to use directly from a git repository:
# gem "my_awesome_lib", :git => "git://path/to/git/repo/my_awesome_lib.git", :branch => "1.0"
# or just use as a gem (perhaps from your very own gem source):
# gem "my_awesome_lib", ">= 1.0.0"
@jvranish
jvranish / DetectDanger.c
Created July 9, 2012 16:13
Example detector function
#include "DetectDanger.h"
bool Detect_Ship_In_Danger(bool * const in_danger,
Position2D const detector1_pos,
Direction2D const detector1_ship_direction_time1,
Direction2D const detector1_ship_direction_time2,
Position2D const detector2_pos,
Direction2D const detector2_ship_direction_time1,
Direction2D const detector2_ship_direction_time2,
Position2D const hazard_pos,
@jvranish
jvranish / arctan.py
Created April 25, 2012 02:00
Example Implementation of arctan(x)
def arctan(n, x):
if x > 1.0:
return math.pi/2.0 - my_preferred_arctan_implementation(n, 1/x)
else:
return my_preferred_arctan_implementation(n, x)
@jvranish
jvranish / WordpressIsEatingMyHaskell.hs
Created February 16, 2012 21:04
WordpressIsEatingMyHaskell
let result = do
account <- getAccount person
lastTransaction <- getLastTransaction account
getAmount lastTransaction
case result of
Nothing -> putStrLn "Oh noes!"
Just a -> putStrLn ("The amount was: " ++ show a)
-- Or really, I'd actually do this:
@jvranish
jvranish / AST.hs
Created December 31, 2011 20:50
Preliminary AST
{-#Language GeneralizedNewtypeDeriving #-}
module Language.TheExperiment.AST where
import Text.Parsec.Pos
import Language.TheExperiment.Type
data Literal = StringLiteral String
| CharLiteral Char
| IntegerLiteral Integer
#ifndef MODULEA_H
#define MODULEA_H
#include "moduleB.h"
typedef struct
{
...
} ModuleAType;
@jvranish
jvranish / FixedListExample.hs
Created October 10, 2011 13:41
Example of some nice properties of fixed lists due to them being applicative functors
import Data.FixedList -- this doesn't come with haskell, do a 'cabal install fixed-list' to install it
-- or get it from here: http://hackage.haskell.org/package/fixed-list-0.1.5
-- more documentation on this library is here: http://hackage.haskell.org/packages/archive/fixed-list/0.1.5/doc/html/Data-FixedList.html
-- These are all built in haskell modules
import Control.Applicative
import Data.Foldable
import Prelude hiding (sum, concat)