Skip to content

Instantly share code, notes, and snippets.

-- http://www.seas.upenn.edu/~cis194/hw/06-laziness.pdf
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE InstanceSigs #-}
{-# OPTIONS_GHC -fno-warn-missing-methods #-}
fib :: Integer -> Integer
fib 0 = 0
fib 1 = 1
fib n = fib (n - 1) + fib (n - 2)
-- http://www.seas.upenn.edu/~cis194/hw/10-applicative.pdf
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE TupleSections #-}
module AParser where
import Control.Applicative
import Data.Char
module AParser (Parser, runParser, satisfy, char, posInt) where
import Control.Applicative
import Data.Char
newtype Parser a = Parser { runParser :: String -> Maybe (a, String) }
satisfy :: (Char -> Bool) -> Parser Char
satisfy p = Parser f
where
-- http://www.seas.upenn.edu/~cis194/hw/12-monads.pdf
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Risk where
import Control.Monad
import Control.Monad.Random
import Control.Applicative
import Data.List
import Data.Monoid
@scott-fleischman
scott-fleischman / Thoughts-Citations-Twitter.txt
Last active August 29, 2015 14:15
Thoughts on Citations on Twitter
Thoughts on Citations on Twitter
I often post quotes on Twitter without citing the source. I have a few
reasons for doing that.
First, Twitter is a limited medium for expression, and as such, I
usually find that the quote I want to tweet does not fit within 140
characters. Limiting the expression even more by including a citation
is too burdensome. Likewise, I don't want to reply to every one of my
tweets with the citation—that would be too many tweets. It's
@scott-fleischman
scott-fleischman / Naive.hs
Last active August 29, 2015 14:15
Unfaithful Sieve vs Naive Prime Algorithm - See "The Genuine Sieve of Eratosthenes" by Melissa E. O'Neill
module Main where
primes = 2 : [x | x <- [3..], isprime x]
isprime x = all (\p -> x `mod` p > 0) (factorsToTry x)
where
factorsToTry x = takeWhile (\p -> p*p <= x) primes
main = do
let ps = take 10000 primes
putStrLn $ (show . length $ ps) ++ " primes."
@scott-fleischman
scott-fleischman / Zipper.hs
Last active August 29, 2015 14:15
Huet Zipper
-- See "The Zipper" by Huet 1997
module Main where
import Control.Applicative
import Control.Monad
import Data.Either
data Tree a =
Item a
@scott-fleischman
scott-fleischman / AgdaGreek4.agda
Last active August 29, 2015 14:16
Greek Script in Agda
module AgdaGreek4 where
open import Data.Maybe renaming (nothing to ⃠)
open import Data.Vec
open import Relation.Nullary using (¬_)
open import Relation.Binary.PropositionalEquality using (_≢_)
data Case : Set where
lower upper : Case
@scott-fleischman
scott-fleischman / Padme.hs
Created February 27, 2015 20:31
Lists with padding
-- taken from http://stackoverflow.com/questions/21349408/zip-with-default-value-instead-of-dropping-values/21350096#21350096
module Main where
import Control.Applicative
import Data.Traversable
import Data.List
data Padme m = (:-)
{ padded :: [m]
@scott-fleischman
scott-fleischman / english-corpora.md
Last active January 27, 2020 17:48
Ancient Language Resources