Skip to content

Instantly share code, notes, and snippets.

Avatar

Michael Dunsmuir mdunsmuir

View GitHub Profile
View hot-dogs.hs
module Main where
import Control.Monad (when)
import System.Environment (getArgs)
import Data.List (intersperse)
fibo :: [Int]
fibo = 0 : 1 : zipWith (+) fibo (tail fibo)
hotDogsOnDay :: Int -> Int
View y.js
function fix(f) {
return function(x) {
return f(x)(fix(f));
}
}
var fac = function(x) {
if(x == 1) {
return function(_) {
return 1;
View slurm_ffi.rb
# Generated by ffi_gen. Please do not change this file by hand.
require 'ffi'
module Slurm
extend FFI::Library
ffi_lib "slurm"
def self.attach_function(name, *_)
begin; super; rescue FFI::NotFoundError => e
View hanoi.hs
{-# LANGUAGE RankNTypes #-}
import Data.Functor.Identity
import Graphics.Gloss
-- * types
type Lens s a = forall f. Functor f => (a -> f a) -> s -> f s
ix :: Int -> Lens [a] a
View ShowIP.hs
import System.Environment
import Control.Exception
import Control.Monad
import Network.Socket
main = do
args <- getArgs
case args of
[host] -> catch (displayIPs host) $ \e -> do
let err = show (e :: IOException)
View Hudooku.hs
{-# LANGUAGE TupleSections #-}
import System.Environment
import Control.Monad
import qualified Data.Attoparsec.Text as P
import Data.Maybe
import Data.List
import qualified Data.Text as T
import qualified Data.Text.IO as TIO
import qualified Data.Map as M
@mdunsmuir
mdunsmuir / Trie.hs
Last active Aug 29, 2015
given an input 'dictionary' (a list of words) and a string, determine whether the string is an arbitrary concatenation of the words in the dictionary
View Trie.hs
module Trie (
Trie,
empty,
fromList,
insert,
prefixesFor
) where
import Data.Maybe
import Data.List (foldr)
View StateT.hs
{-# LANGUAGE MultiParamTypeClasses,
FunctionalDependencies,
FlexibleInstances #-}
module StateT (
--StateT, runStateT,
State, runState,
MonadState,
module Control.Applicative,
module Control.Monad,
View f-algebras.hs
-- common
data Fix a = Fx (a (Fix a))
unfix :: Fix a -> a (Fix a)
unfix (Fx f) = f
type Algebra f a = f a -> a
cata :: Functor f => (f a -> a) -> Fix f -> a
View PascalsTriangle.hs
module PascalsTriangle (pascalsTriangle) where
import Control.Applicative
import Test.QuickCheck
pascalsTriangle :: [[Int]]
pascalsTriangle = [1] : map row pascalsTriangle
where row prev = zipWith (+) (0 : prev) (prev ++ [0])
-- quickcheck stuff