Skip to content

Instantly share code, notes, and snippets.

@ekmett
ekmett / Space.hs
Created June 7, 2011 14:58
haskell vector spaces
{-# LANGUAGE TypeFamilies, FlexibleContexts, TypeOperators, UndecidableInstances, GeneralizedNewtypeDeriving #-}
module Numeric.Vector.Space where
import Data.Functor.Representable.Trie hiding (Entry)
import Data.Key (Adjustable(..), Key)
import qualified Data.Key as Key
import qualified Data.Heap as Heap
import Data.Heap (Heap, Entry(..))
import qualified Data.List.NonEmpty as NonEmpty
import Data.List.NonEmpty (NonEmpty(..))
@piscisaureus
piscisaureus / pr.md
Created August 13, 2012 16:12
Checkout github pull requests locally

Locate the section for your github remote in the .git/config file. It looks like this:

[remote "origin"]
	fetch = +refs/heads/*:refs/remotes/origin/*
	url = git@github.com:joyent/node.git

Now add the line fetch = +refs/pull/*/head:refs/remotes/origin/pr/* to this section. Obviously, change the github url to match your project's URL. It ends up looking like this:

@sebastiaanvisser
sebastiaanvisser / g0.hs
Created September 10, 2012 08:07
Composing algebras.
{-# LANGUAGE
GADTs
, KindSignatures
, RankNTypes
, TupleSections
, TypeOperators
#-}
module Generics.Morphism where
import Control.Arrow
@nfrisby
nfrisby / InductiveConstraints.hs
Created October 11, 2012 22:09
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)
@jonsterling
jonsterling / Coinduction.hs
Created October 13, 2012 22:46
Idea for codata syntax in Haskell
-- Inspired by http://www2.tcs.ifi.lmu.de/~abel/popl13.pdf
[codata|
codata Stream a where
head :: Stream a -> a
tail :: Stream a -> Stream a
|]
fib :: Stream Nat
[copattern|
@sebastiaanvisser
sebastiaanvisser / g1.hs
Created May 29, 2013 08:36
Composing algebras using Arrow and Applicative.
{-# LANGUAGE GADTs, TypeOperators, TupleSections #-}
module Generics.Algebra where
import Control.Category
import Control.Arrow
import Control.Applicative
import Prelude hiding ((.), id)
import Generics.Combinator
func main () {
let typedHeterogeneousList = true =+= "Hello" =+= 1 =+= HNil()
let first: Bool = typedHeterogeneousList.head()
let second: String = typedHeterogeneousList.tail().head()
let third: Int = typedHeterogeneousList.tail().tail().head()
}
protocol HList {
typealias Head
@tomlokhorst
tomlokhorst / Optional+Unwrap.swift
Last active December 26, 2017 19:50
Unwrap multiple optionals in Swift 1.0
func unwrap<T1, T2>(optional1: T1?, optional2: T2?) -> (T1, T2)? {
switch (optional1, optional2) {
case let (.Some(value1), .Some(value2)):
return (value1, value2)
default:
return nil
}
}
func unwrap<T1, T2, T3>(optional1: T1?, optional2: T2?, optional3: T3?) -> (T1, T2, T3)? {
{-# LANGUAGE AllowAmbiguousTypes #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module NamedTypeclass where
import Prelude hiding (Monoid, mempty, (<>))
@mstewartgallus
mstewartgallus / onekappa.hs
Last active March 29, 2021 08:41
One object kappa/zeta calculus, kind of like reflexive objects but also weird
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE QuantifiedConstraints #-}
import Prelude hiding (id, (.))
import Control.Category
import Control.Monad.State hiding (lift)
class Category k => Terminal k where
term :: k a ()