Skip to content

Instantly share code, notes, and snippets.

@pminten
pminten / event-server_test.exs
Created January 18, 2014 10:43
A file that mysteriously hangs the compiler
ExUnit.start
defmodule EventServerTest do
use ExUnit.Case, async: false
test "spawn and crash" do
pid = Process.spawn_link(fn ->
exit :foo
end)
:timer.sleep(1000)
@pminten
pminten / test_teardown.exs
Last active January 3, 2016 18:49
Tests in assertions aren't raised
ExUnit.start
defmodule TeardownTest do
use ExUnit.Case
def teardown do
assert 1 == 2
end
test "foo" do
@pminten
pminten / computed_lazyness.idr
Created April 23, 2014 16:53
Functions can be lazy based on computations
module Main
pl : Bool -> Type -> Type
pl True t = Lazy t
pl False t = t
-- Only defined for True.
partial
onlyTrue : Bool -> Bool
onlyTrue True = True
@pminten
pminten / weird_labels.idr
Last active August 29, 2015 14:01
Doesn't run, not sure how to make this work.
module Main
import Effect.State
import Effect.Exception
printInner : { [ STATE Int, EXCEPTION Int ] } Eff m ()
printInner = return ()
main : IO ()
main = runInit ['St := 1, 'Ex := 1] $ do
@pminten
pminten / log.idr
Created May 7, 2014 10:06
A simple logger
module Main
import Effect.State
import Effect.StdIO
import Effect.System
data Level = Debug | Info | Warn | Error | Critical
-- Apparently Idris doesn't have deriving yet, so define those instances
-- manually.
@pminten
pminten / eq_laws.hs
Created May 8, 2014 17:40
Using the ClassLaws lib for a trivial example
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE EmptyDataDecls #-}
module Main where
import Test.ClassLaws
data EqLaw1 a
class Eq a => EqLaws a where
@pminten
pminten / update-bench.rkt
Created August 8, 2014 12:24
Racket code to visualize how bad association lists are as an updating dictionary
#lang racket
; Quick and ugly benchmark to see how if association lists for
; smallish lists are quicker to update than hash tables.
; To run: open in DrRacket and press the Run button.
(require plot)
; List of words of varying length.
### Keybase proof
I hereby claim:
* I am pminten on github.
* I am pminten (https://keybase.io/pminten) on keybase.
* I have a public key whose fingerprint is D3E4 F718 A175 34B4 6E8D 3B81 9B6C 1FB0 7226 79BA
To claim this, I am signing this object:
@pminten
pminten / number_line.idr
Created February 16, 2015 18:04
Example of using a simple codata structure
%default total
-- An infinite list of numbers (.., -2, -1, 0, 1, 2, ...)
-- with a way to go forward and backward.
codata NumberLine = NL Int NumberLine NumberLine
-- Make a number line starting at a particular point.
--
-- Try changing "codata" above into "data". This function will fail to compile
-- as it's not guaranteed to terminate.