Skip to content

Instantly share code, notes, and snippets.

@LeifW
LeifW / Compare.hs
Created July 6, 2015 07:13
Compare version in Stackage-nightly and habs
module Compare where
import PkgDB (readDb, pkgName, pkgVersion)
import Distribution.Version (versionBranch)
import qualified Data.Map.Strict as Map
import Data.Map.Strict (Map)
import Data.List.Split (splitOn)
import Data.Bifunctor (bimap)
import Control.Arrow ((&&&))
@LeifW
LeifW / PKGBUILD
Created July 1, 2015 04:03
Current haskell-reflection PKGBUILD
# Maintainer: Leif Warner <[email protected]>
_hkgname=reflection
pkgname=haskell-reflection
pkgver=1.5.2.1
pkgrel=1
pkgdesc="Reifies arbitrary terms into types that can be reflected back into terms"
url="http://hackage.haskell.org/package/${_hkgname}"
license=('custom:BSD3')
arch=('i686' 'x86_64')
depends=('ghc' 'haskell-tagged<1' 'haskell-template-haskell')
@LeifW
LeifW / NumType.idr
Last active May 23, 2020 07:57
A Num instance for Type
import Data.Vect
%default total
Num Type where
(+) = Either
(*) = Pair
fromInteger 0 = Void
fromInteger 1 = Unit
fromInteger 2 = Bool
import Data.Fin
record DivMod : (dividend, divisor : Nat) -> Type where
result : (quotient : Nat) ->
(remainder : Fin divisor) ->
(property : dividend = finToNat remainder + quotient * divisor) ->
DivMod dividend divisor
data X : Type where
Y : Type -> X
getA : X -> Type
getA (Y x) = x
f : X -> (getA X)
--f (Y Int) = 10
foo : Maybe Type -> Type
foo Nothing = String
foo (Just x) = x
a : foo Nothing
a = "Hello"
b : foo (Just Int)
b = 10
@LeifW
LeifW / letter.md
Created February 20, 2015 23:04
My Illustrious Friend, and Joy of my Liver!

The thing you ask of me is both difficult and useless. Although I have passed all my days in this place, I have neither counted the houses nor inquired into the number of the inhabitants; and as to what one person loads on his mules and the other stows away in the bottom of his ship, that is no business of mine. But, above all, as to the previous history of this city, God only knows the amount of dirt and confusion that the infidels may have eaten before the coming of the sword of Islam. It were unprofitable for us to inquire into it. O my soul! O my lamb! seek not after the things which concern thee not. Thou camest unto us and we welcomed thee: go in peace.

Of a truth thou hast spoken many words and there is no harm done, for the speaker is one and the listener is another. After the fashion of thy people thou hast wandered from one place to another, until thou art happy and content in none. We (praise be to God) were born here, and never desire to quit it. Is it possible, then, that the idea of a general i

val dateGen: Gen[DateTime] = for {
year <- Gen.choose(2014, 2015)
month <- Gen.choose(1, 12)
day <- Gen.choose(1, month match {
case 2 => 28
case 4 | 6 | 9 | 11 => 30
case _ => 31
})
hour <- Gen.choose(0, 23)
minute <- Gen.choose(0, 59)
@LeifW
LeifW / optionOp.scala
Last active August 29, 2015 14:10
lift binary op to option (a la A: Semigroup => Option[A]: Monoid instance)
class Ring[A](o1: Option[A], f: (A, A) => A) {
def or(o2: Option[A]) = (o1, o2) match {
case (Some(x), Some(y)) => Some(f(x, y))
case (Some(_), None) => o1
case (None, _) => o2
}
def and(o2: Option[A]) = (o1, o2) match {
case (Some(x), Some(y)) => Some(f(x, y))
case _ => None
}