This file contains 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
-- Standard Prelude definitions | |
-- data Ordering = LT | EQ | GT | |
-- class Eq a => Ord a where | |
-- compare :: a -> a -> Ordering | |
isOrdered :: Ord a => [a] -> Bool | |
isOrdered (x:y:xs) = case compare x y of | |
GT -> False | |
_ -> isOrdered (y:xs) | |
isOrdered _ = True |
This file contains 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
import Signal | |
import Window | |
(block_width, block_height) = (100, 100) | |
speed = 1.5 | |
dimensions = Window.dimensions | |
width = lift fst dimensions | |
height = lift snd dimensions |
This file contains 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
{-# LANGUAGE DataKinds, KindSignatures, GADTs #-} | |
data Nat = Zero | Succ Nat | |
-- Bounded naturals | |
data Fin :: Nat -> * where | |
FZ :: Fin (Succ n) | |
FS :: Fin n -> Fin (Succ n) | |
data Vect (n :: Nat) a where |
This file contains 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
{-# LANGUAGE DataKinds, KindSignatures, GADTs #-} | |
data Nat = Zero | Succ Nat | |
data Even :: Nat -> * where | |
Even_base :: Even Zero | |
Even_induct :: Even k -> Even (Succ (Succ k)) | |
data Odd :: Nat -> * where | |
Odd_base :: Odd (Succ Zero) |
This file contains 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 | |
data Literal : Type where | |
float : Float -> Literal | |
-- A PostScript program which takes a stack of one size to a stack of | |
-- another size. | |
-- (PostScript m n) takes a stack of size m and returns a stack of size n. | |
data PostScript : Nat -> Nat -> Type where | |
nop : PostScript n n |
This file contains 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
newtype Fix f = Fix (f (Fix f)) | |
-- Define List as the fixed point of a type operator | |
data ListR a t = Nil | Cons a t | |
type List a = Fix (ListR a) | |
-- The type operator ListR represents "one layer" of the structure | |
-- of List. We can do something fold-like with it. | |
-- My question is, is there a name for f? It's like a catamorphism | |
-- but doesn't recurse into the data. |
This file contains 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
#!/usr/bin/env bash | |
# Blacklist commit 1abfdd7 | |
root=$(awk '{print $2}') | |
objects=$(git rev-list --objects $root | awk '{print $1}') | |
echo $objects | grep 1abfdd7cb8c67ead50757ea596aa0f01b0ab1389 > /dev/null | |
if [[ $? -eq 0 ]] | |
then |
This file contains 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
import System.Environment | |
sumSquares :: (Integral a) => a -> a | |
sumSquares n = n*(n+1)*(2*n+1) `div` 6 | |
sumCubes :: (Integral a) => a -> a | |
sumCubes n = ((n^2 + n) `div` 2)^2 | |
main = do | |
args <- getArgs |
This file contains 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
import Control.Monad | |
import Control.Monad.State.Lazy | |
-- Simple way to get Fibonacci numbers using monad transformers | |
fibT :: (Monad m, Num a) => StateT a (StateT a m) () | |
fibT = get >>= \x -> lift get >>= \y -> put y >> (lift . put $ x + y) | |
-- Get the nth Fibonacci number | |
fib :: Num a => Int -> a | |
fib n = execState (execStateT (replicateM_ n fibT) 0) 1 |
This file contains 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 (main) where | |
import Control.Monad | |
import Data.Char | |
import System.IO | |
import System.Environment | |
import System.Random | |
import System.Exit |
OlderNewer