Skip to content

Instantly share code, notes, and snippets.

View timjb's full-sized avatar

Tim Baumann timjb

View GitHub Profile
@timjb
timjb / SortedList.idr
Created February 17, 2014 01:40
Mergesort in Idris
module SortedList
-- Based on http://mazzo.li/posts/AgdaSort.html
import Decidable.Decidable
import Decidable.Order
import Uninhabited
%default total
@timjb
timjb / Trominoes.hs
Created March 24, 2014 02:05
Visualization of an inductive proof using diagrams
{-# LANGUAGE NoMonomorphismRestriction #-}
-- http://www.cut-the-knot.org/Curriculum/Geometry/Tromino.shtml
module Trominoes where
import Diagrams.Prelude
import Diagrams.Backend.SVG
import Diagrams.Backend.SVG.CmdLine
@timjb
timjb / kartoffel-maronen-suppe.markdown
Last active August 29, 2015 13:58
Kartoffel-Maronen-Suppe

Kartoffel-Maronen-Suppe

Zutaten

  • 400g Maronen
  • 1 Zwiebel
  • 2 Knoblauchzehen
  • 4-5 Kartoffeln
  • 1/2l Brühe
  • 200g Sahne
@timjb
timjb / CosimplicialIdentities.agda
Last active August 29, 2015 13:59
Kosimpliziale Identitäten
-- Vorlesung "Homologische Algebra", Übungsblatt 1, Aufgabe 2
module CosimplicialIdentities where
open import Function
open import Data.Product
open import Data.Empty using (⊥; ⊥-elim)
open import Data.Nat hiding (_≤_; _<_; compare) renaming (suc to s)
open import Data.Nat.Properties hiding (strictTotalOrder)
open import Data.Fin hiding (compare)
@timjb
timjb / output.txt
Last active August 29, 2015 14:00
Rewrite rules, postulates and reduction in Idris
Idris> :load test.idr
*test> xAssoc (MkX (3 + 4)) (MkX 5)
MkX 12 : X 12
*test> xAssoc' (MkX (3 + 4)) (MkX 5)
replace (sym (plusAssociative' 3 4 5))
xPlus
(MkX 7)
(MkX 5) : X 12
*test> xAssoc'' (MkX (3 + 4)) (MkX 5)
MkX 12 : X 12
{-# LANGUAGE GADTs #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE ImpredicativeTypes #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE NoMonomorphismRestriction #-}
{-# LANGUAGE OverlappingInstances #-}
{-# LANGUAGE LiberalTypeSynonyms #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE TypeOperators #-}
module WithFunctor where
newtype (:.:) f g a = Comp { getComp :: f (g a) } deriving (Show, Eq)
instance (Functor f, Functor g) => Functor (f :.: g) where
fmap f = Comp . fmap (fmap f) . getComp
@timjb
timjb / BoundedExistentials.hs
Created August 28, 2014 15:50
Bounded Existential types in Haskell
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE ConstraintKinds #-}
module BoundedExistentials where
import GHC.Exts (Constraint)
class Constraint1 c where
type Constr1 c a :: Constraint
@timjb
timjb / LazyList.idr
Created August 30, 2014 11:20
Lazy lists in Idris
module Data.LazyList
%default total
%access public
data LazyListCell a = Nil | (::) a (Lazy (LazyListCell a))
LazyList : Type -> Type
LazyList a = Lazy (LazyListCell a)
@timjb
timjb / RealTimeQueue.idr
Created August 31, 2014 01:45
Purely functional size indexed queues supporting O(1) head and snoc operations in Idris
module Data.RealTimeQueue
-- adapted from Chris Okasaki's `Purely Functional Data Structures`, figure 7.1
%default total
data LazyVectCell : Nat -> Type -> Type where
Nil : LazyVectCell Z a
(::) : (x : a) -> (xs : Lazy (LazyVectCell n a)) -> LazyVectCell (S n) a