Skip to content

Instantly share code, notes, and snippets.

View rampion's full-sized avatar

Noah Luck Easterly rampion

  • Mercury Technologies
View GitHub Profile
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
module HFilter where
data a :* b = a :* b
deriving (Show, Eq)
infixr 5 :*
hlist :: Int :* String :* Int :* Maybe Float :* ()
module Chainable (
(==.), (.==.), (.==),
(/=.), (./=.), (./=),
(<.), (.<.), (.<),
(>.), (.>.), (.>),
(<=.), (.<=.), (.<=),
(>=.), (.>=.), (.>=),
) where
-- start Eq chain
{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances #-}
module Chainable (
(==?), (/=?),
(<?), (<=?), (>?), (>=?),
isJust
) where
import Data.Maybe (isJust)
import Control.Monad (liftM, liftM2)
@rampion
rampion / 0_RowPolymorphism_Primitives.hs
Created February 16, 2012 20:51
Playing with Factor's Row Polymorphism in Haskell
{-# LANGUAGE TypeOperators #-}
-- inspired by "Why concatenative programming matters."
-- (http://evincarofautumn.blogspot.com/2012/02/why-concatenative-programming-matters.html)
--
-- playing with adapting row polymorphism to Haskell, because, hey, why not?
module RowPolymorphism.Primitives (
(:>)(), Stack,
lift, quote, (!),
dip, dup, over, swap, drop, call
) where
@rampion
rampion / diagram.txt
Created February 6, 2012 22:09
demonstration of inserting 13 into a splay tree
Insert 13
10
/ \
5 15
/ \
11 20
\
13
@rampion
rampion / HigherOrderVsCurried.txt
Created January 22, 2012 05:47
When is a tuple not a tuple, and other scala type error ambiguities
scala> def k( j : (Int => Int) => Int ) : Int = j(_+1)
k: (j: Int => Int => Int)Int
scala> def p(q : Int => Int) : Int = q(0)
p: (q: Int => Int)Int
scala> def z = (x : Int) => (y : Int) => x + y
z: Int => Int => Int
scala> k(p)
@rampion
rampion / ImplicitTest.scala
Created January 12, 2012 18:10
A demonstration of using implicit parameters to mimic typeclasses.
abstract class SemiGroup[A] {
def add(x: A, y: A): A
}
abstract class Monoid[A] extends SemiGroup[A] {
def unit: A
}
object ImplicitTest extends App {
def sum[A](xs: List[A])(implicit m: Monoid[A]): A =
if (xs.isEmpty) m.unit
module Palindrome where
-- an adaptation of Johan Jeuring's algorithm for finding maximal palindrome lengths
-- (http://johanjeuring.blogspot.com/2007/08/finding-palindromes.html)
import Control.Arrow ((***))
-- find the maximal lengths of the palindromes
-- centered before, on, and after each element in the list
maximalPalindromeLengths :: Eq a => [a] -> [Int]
maximalPalindromeLengths as = grow 0 [] as as []
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script>
jQuery(function($){
var draw = function(shape){
var a = 50;
var b = a*shape[0];
var c = a*shape[1];
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.5.2/jquery.min.js"></script>
<script>
jQuery(function($){
var draw = function(shape){
var a = 50;
var b = a*shape[0];
var c = a*shape[1];