This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- http://www.seas.upenn.edu/~cis194/hw/10-applicative.pdf | |
{-# LANGUAGE InstanceSigs #-} | |
{-# LANGUAGE TupleSections #-} | |
module AParser where | |
import Control.Applicative | |
import Data.Char |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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." |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- See "The Zipper" by Huet 1997 | |
module Main where | |
import Control.Applicative | |
import Control.Monad | |
import Data.Either | |
data Tree a = | |
Item a |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- 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] |
OlderNewer