Skip to content

Instantly share code, notes, and snippets.

View puffnfresh's full-sized avatar

Brian McKenna puffnfresh

View GitHub Profile
@puffnfresh
puffnfresh / Option.js
Created May 29, 2012 04:41 — forked from jaredbc/Option.js
JS option
function some(a) {
return {
fold: function(f, _) {
return f(a);
},
getOrElse: function(e) {
return a;
},
orElse: function() {
return some(a);
let arrayMonad = {
return: \x -> [x]
bind: \x f -> Array.prototype.concat.apply [] (x.map f)
}
let array = [0, 1, 2, 3, 4, 5, 6, 7, 8, 9]
console.log (do arrayMonad
x <- array
y <- array
import language.implicitConversions
class AmbiguousStringAdd {
def +(b: String) = ???
}
implicit def amb1any2stringadd(a: Any) = new AmbiguousStringAdd
implicit def amb2any2stringadd(a: Any) = new AmbiguousStringAdd
class A {}
(function(global) {
global.def = function define(name, dependencies, moduleFactory) {
global.amdModules = global.amdModules || {};
if (Object.prototype.toString.call(dependencies) != '[object Array]' && typeof dependencies !== 'function')
throw new Error('dependencies must be an array. moduleFactory must be a function.');
global.amdModules[name] = {
'moduleFactory': moduleFactory || dependencies,
'dependencies': typeof (moduleFactory) === 'undefined' ? [] : dependencies
data GenericThing = SpecificThing Char | BadThing
isSpecificThing :: GenericThing -> Bool
isSpecificThing (SpecificThing _) = True
isSpecificThing _ = False
foo :: [GenericThing] -> GenericThing
foo xs
| null xs = error "Empty GenericThings"
| all isSpecificThing xs = head xs
@puffnfresh
puffnfresh / Main.hs
Last active December 23, 2015 15:19 — forked from mkscrg/Main.hs
module Main where
import Data.List (inits)
import Data.List.Split (splitOn)
main :: IO ()
main = print $ wordIndexes "Hello test World"
wordIndexes :: String -> [(Int, String)]
wordIndexes s =
module Primes where
open import Level using (_⊔_)
open import Coinduction
open import Function
open import Data.Empty
open import Data.Unit
open import Data.Nat
open import Data.Nat.Properties
open import Data.Nat.Divisibility
module Reverse where
open import Data.List as List hiding (reverse)
open import Data.List.Properties
open import Relation.Binary.PropositionalEquality
record ReverseLike (reverse : ∀ {A : Set} → List A → List A) : Set₁ where
constructor rl
field
reverse0 : ∀ {A} → reverse {A} [] ≡ []
import scala.language.higherKinds
trait Functor[F[_]] {
def fmap[A, B](f: A => B): F[A] => F[B]
}
trait Apply[F[_]] {
val functor: Functor[F]
def ap[A, B](f: F[A => B]): F[A] => F[B]
@puffnfresh
puffnfresh / Syntax.scala
Created October 7, 2015 05:53 — forked from shajra-cs/Syntax.scala
A clever use of unapply to get syntax on Scalaz process for error handling
package shajra.extn.scalaz.stream
import scalaz.{ Bind, Traverse, Unapply }
import scalaz.stream.Process
trait Syntax {
implicit class ProcessSyntax[F[_], A](self: Process[F, A]) {