Skip to content

Instantly share code, notes, and snippets.

@hardentoo
hardentoo / random_monad_example.hs
Created July 12, 2018 06:32 — forked from ijt/random_monad_example.hs
Example of how to use the Random monad in Haskell
-- cabal install MonadRandom
-- ghc random_monad_example
-- ./random_monad_example
-- The code here is stolen from a comment in the MonadRandom source code.
import Control.Monad.Random
die :: RandomGen g => Rand g Int
die = getRandomR (1,6)
module STLC where
-- Simple substitution à la Conor, as described in http://strictlypositive.org/ren-sub.pdf
id : {A : Set} → A → A
id x = x
data Type : Set where
* : Type
_⇒_ : (S T : Type) → Type
{-
Dependently typed metaprogramming (in Agda)
Conor McBride, 2013
Dependently typed programming
Conor McBride, 2011
-}
@hardentoo
hardentoo / he-get.hs
Created June 11, 2018 21:57
A simple wget style program using Haskell and http-enumerator
{-# LANGUAGE OverloadedStrings #-}
import Control.Monad.IO.Class (liftIO)
import Network (withSocketsDo)
import System.Environment (getArgs, getProgName)
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Lazy.Char8 as LBS
import qualified Data.CaseInsensitive as CI
import qualified Network.HTTP.Enumerator as HE
@hardentoo
hardentoo / new-gplv3-full-project.hsfiles
Created June 9, 2018 20:11 — forked from queertypes/new-gplv3-full-project.hsfiles
Haskell Stack template: GPL-3, doctests, hlint, many other goodies
{-# START_FILE {{name}}.cabal #-}
name: {{name}}
version: 0.1.0.0
synopsis: Initial project template from stack
description: Please see README.md
license: GPL-3
license-file: LICENSE
author: {{author-name}}{{^author-name}}Author name here{{/author-name}}
maintainer: {{author-email}}{{^author-email}}example@example.com{{/author-email}}
copyright: {{copyright}}{{^copyright}}{{year}}{{^year}}2017{{/year}} {{author-name}}{{^author-name}}Author name here{{/author-name}}{{/copyright}}
@hardentoo
hardentoo / list-all-repos.py
Created June 4, 2018 18:34 — forked from ralphbean/list-all-repos.py
Script to list all repos for a github organization
#!/usr/bin/env python
""" Print all of the clone-urls for a GitHub organization.
It requires the pygithub3 module, which you can install like this::
$ sudo yum -y install python-virtualenv
$ mkdir scratch
$ cd scratch
$ virtualenv my-virtualenv
@hardentoo
hardentoo / histo-futu.hs
Created May 30, 2018 23:06 — forked from jtobin/histo-futu.hs
Time-traveling recursion schemes
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE TypeFamilies #-}
import Control.Comonad.Cofree
import Control.Monad.Free
import Data.Functor.Foldable
oddIndices :: [a] -> [a]
oddIndices = histo $ \case
Nil -> []
@hardentoo
hardentoo / InductiveConstraints.hs
Created May 30, 2018 22:32 — forked from nfrisby/InductiveConstraints.hs
simple demo of "proving" in Haskell via singleton types
{-# LANGUAGE RankNTypes, TypeFamilies, DataKinds, TypeOperators,
ScopedTypeVariables, PolyKinds, ConstraintKinds, GADTs,
MultiParamTypeClasses, FlexibleInstances, UndecidableInstances,
FlexibleContexts #-}
module InductiveConstraints where
import GHC.Prim (Constraint)
@hardentoo
hardentoo / hoogle.md
Created May 29, 2018 09:41 — forked from chrisdone/hoogle.md
stack hoogle

Introducing the stack hoogle feature!

With the release of hoogle5, we can now hoogle all local packages.

This let us implement stack hoogle, which is on the master branch of stack, but is not yet on a stack release. We'd like you to try it out before we do!

To upgrade to the latest stack from git, use:

@hardentoo
hardentoo / SplayTree.hs
Created May 26, 2018 01:05 — forked from m2ym/SplayTree.hs
Toy Splay Tree in Haskell
import Data.Maybe (isJust)
data Tree a = Leaf | Node (Tree a) a (Tree a)
replace :: a -> Tree a -> Tree a
replace a Leaf = Node Leaf a Leaf
replace a (Node l _ r) = Node l a r
rotateR :: Tree a -> Tree a
rotateR (Node (Node x a y) b z) = Node x a (Node y b z)