Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE PostfixOperators #-}
{-# LANGUAGE TemplateHaskell #-}
module Main where
import Control.Lens
import Control.Monad.State
import Prelude hiding ((++))
(++) :: (Num a, MonadState s m) => LensLike' ((,) a) s a -> m a
warning: Nix search path entry ‘/home/nathan/.nix-defexpr/channels/nixpkgs’ does not exist, ignoring
these derivations will be built:
/nix/store/7rxarwnalkax5v5fvf1hxrnwql0y3dl9-python2.7-pytest-3.0.7.drv
/nix/store/268bwg3nylw2f0v895231msmqxrpknpl-python2.7-Babel-2.3.4.drv
/nix/store/g10lnnhpq883v5x7dhrlylqvnpy2377b-python2.7-six-1.10.0.drv
/nix/store/1d404igglldx5n0qmdr2m3ccmhz6lw3j-python2.7-unittest2-1.1.0.drv
/nix/store/cp6j75wd7wkgi16i23pls9qrdjxc0mkd-python2.7-funcsigs-1.0.2.drv
/nix/store/ji8ljdzkqsgvxw5s5kl6fz7h04pzjc68-python2.7-mock-2.0.0.drv
/nix/store/5h39f0abz2rbzm97igw8z1b14mhlhmwb-python2.7-apipkg-1.4.drv
/nix/store/x77ysrxl9m7vw7bjzj469mvm6v0xsivf-python2.7-execnet-1.4.1.drv
module BF where
data Token : Set where
Plus : Token
Minus : Token
Less : Token
More : Token
Period : Token
Comma : Token
Open : Token
@Taneb
Taneb / Test.hs
Created September 8, 2016 17:50
isTreeOrdered causing headaches
{-# OPTIONS_GHC -fno-warn-orphans #-}
module Main where
import Data.Treap
import Test.QuickCheck
instance (Arbitrary h, Arbitrary t, Arbitrary a, Ord h, Ord t) => Arbitrary (Treap h t a) where
arbitrary = sized $ \n -> do
s <- choose (0, n)
theory PFDS
imports Main
begin
datatype 'a Tree = E | T "'a Tree" 'a "'a Tree"
primrec trmax :: "'a ⇒ 'a Tree ⇒ 'a" where
"trmax a E = a" |
"trmax _ (T _ here right) = trmax here right"
@Taneb
Taneb / sirpent.rs
Created June 5, 2016 13:39
Proof of concept for Rust implementation of sirpent
trait Vector {
type Direction;
fn distance(&self, other : &Self) -> Self;
fn neighbour(&self, direction : Self::Direction) -> Self;
}
trait Grid {
type Vector : Vector;
fn dimensions(&self) -> Vec<isize>;
@Taneb
Taneb / primes.rs
Created September 7, 2015 11:35
Sieve of Eratosthenes in Rust
pub fn main() {
let limit = 1000000;
let mut sieve = Vec::with_capacity(limit-2);
for _ in (2..limit) {
sieve.push(true);
}
for ix in(0..limit-2) {
if sieve[ix] {
println!("{}", ix + 2);
import Graphics.Element exposing (Element)
import Graphics.Collage exposing (collage, toForm, text)
import Signal exposing ((<~))
import Time exposing (Time, every)
import Date exposing (fromTime, hour, minute, second)
import String exposing (padLeft)
import Text exposing (Text, fromString, monospace, height)
import List exposing (map)
main = showTime <~ every Time.second
module Nat where
newtype Nat = Nat [Nat] deriving (Show, Eq)
double :: Nat -> Nat
double (Nat []) = Nat []
double (Nat (a : as)) = Nat (succ a : as)
half :: Nat -> Nat
half (Nat []) = Nat []
@Taneb
Taneb / Q.hs
Created February 27, 2015 22:10
A quine in Haskell
module Main where
a, b :: String
a = "module Main where\n\na, b :: String\na = \""
b = "\"\n\nexpand :: Char -> String\nexpand '\\n' = \"\\\\n\"\nexpand '\"' = \"\\\\\\\"\"\nexpand '\\\\' = \"\\\\\\\\\"\nexpand c = [c]\n\nmain :: IO ()\nmain = do\n putStr a\n putStr $ a >>= expand\n putStr \"\\\"\\nb = \\\"\"\n putStr $ b >>= expand\n putStr b\n"
expand :: Char -> String
expand '\n' = "\\n"
expand '"' = "\\\""
expand '\\' = "\\\\"