Skip to content

Instantly share code, notes, and snippets.

View owen-d's full-sized avatar

Owen Diehl owen-d

View GitHub Profile
@owen-d
owen-d / sublist.hs
Created July 21, 2019 18:38
contiguous sublists of n length in haskell
sublists :: Int -> [a] -> [[a]]
sublists n xs = filter (\x -> length x == n) $ contiguous n xs
where
contiguous _ [] = []
contiguous n (x:xs) =
take n (x:xs) : contiguous n xs
@owen-d
owen-d / combinators.ts
Created May 20, 2019 20:22
y,z combinators, ts edition
// Y= λf.(λx.f (x x)) (λx.f (x x))
y = f => {
const g = x => f(x(x))
return g(g)
}
// seems equivalent to Z for use in applicative order langs
// Y1= λf.(λx. (λy. f (xx) y))(λx. (λy. f (xx) y))
y1 = f => {
@owen-d
owen-d / Maybe.ts
Last active May 6, 2019 20:14
maybe typescript
// This excludes us from trying to use (Maybe null) sensibly.
export type Maybe<T> = T | null
export function isJust<T>(x: Maybe<T>): x is T {
return x !== null
}
export function isNothing<T>(x: Maybe<T>): x is null {
@owen-d
owen-d / probability.hs
Created January 18, 2019 17:46
functors, monads, and probability
{-# LANGUAGE DeriveFunctor #-}
module Prob where
import Control.Monad (forM_)
import qualified Data.Map as M
import Text.Printf (printf)
newtype Prob a = Prob {unProb :: [(a, Double)]} deriving (Functor, Show)
@owen-d
owen-d / Lib.SubMsg.elm
Last active July 11, 2017 18:08
issue subtyping elm msgs
module Lib.SubMsg exposing (..)
type SubMsg
= SubMsgA
| SubMsgB
@owen-d
owen-d / ezFib.js
Created November 2, 2015 19:21
ez fibonacci
function fib() {
var head = 0;
var tail = 0;
return function() {
var res = head + tail;
//just for the beginning, so we get 2 rounds with a result of 1
if (!res) {
head = 1;