Skip to content

Instantly share code, notes, and snippets.

@ElvishJerricco
ElvishJerricco / hie.nix
Created June 4, 2017 19:40
Nix expression for haskell-ide-engine
{ stdenv, fetchFromGitHub, haskell, haskellPackages }:
with haskell.lib;
let hie-src = stdenv.mkDerivation {
name = "haskell-ide-engine";
src = fetchFromGitHub {
owner = "haskell";
repo = "haskell-ide-engine";
rev = "cb600ac290d91a0fc967487fa17a83f9f58fe3d6";
sha256 = "1xhq1y2dbjiqn3i9gk5a2lv0iyjlkiv9r1xm99ampv2j9aksn6fj";
import Criterion
import Criterion.Main
import HSTrav
import Data.List
import qualified Data.Sequence as Seq
main :: IO ()
main = defaultMain
[ bench "heap-sort" (nf sortTraversable [1000000,999999 .. 1 :: Int])
@ElvishJerricco
ElvishJerricco / OpenUnion.hs
Created April 15, 2016 07:59
Data.Dependent.OpenUnion
{-# LANGUAGE ConstraintKinds #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
@FunctionalInterface
public interface FunctionX<X extends Throwable, T, R> {
R apply(T t) throws X;
default <V> FunctionX<X, V, R> compose(FunctionX<? extends X, ? super V, ? extends T> before) {
Objects.requireNonNull(before);
return (V v) -> apply(before.apply(v));
}
default <V> FunctionX<X, T, V> andThen(FunctionX<? extends X, ? super R, ? extends V> after) {
Objects.requireNonNull(after);
return (T t) -> after.apply(apply(t));
@ElvishJerricco
ElvishJerricco / SupplierX.java
Last active October 18, 2015 20:18
SupplierX
public interface SupplierX<X extends Throwable, T> {
T get() throws X;
}
public interface PredicateX<X extends Throwable, T> {
boolean test(T t) throws X;
default PredicateX<X, T> and(PredicateX<? extends X, ? super T> other) {
Objects.requireNonNull(other);
return (t) -> test(t) && other.test(t);
}
default PredicateX<X, T> negate() {
return (t) -> !test(t);
@ElvishJerricco
ElvishJerricco / ConsumerX.java
Last active October 18, 2015 20:17
ConsumerX
@FunctionalInterface
public interface ConsumerX<X extends Throwable, T> {
void accept(T t) throws X;
default ConsumerX<X, T> andThen(ConsumerX<? extends X, ? super T> after) {
Objects.requireNonNull(after);
return (T t) -> { accept(t); after.accept(t); };
}
}
public final class OptionalX<T> {
private static final OptionalX<?> EMPTY = new OptionalX<>();
private final T value;
private OptionalX() {
this.value = null;
}
public static<T> OptionalX<T> empty() {
data Some1 = Some1 { name :: String } | Some1'
data Some2 = Some2 { name :: Int } | Some2'
-- Would be generated
name :: some <: Some1 + Some2 - { Some1', Some2' } -> {
case s of
Some1 name = name
Some2 name = name
| s <- some
}
index :: l <: [a] - ([]) -> i <: { n <- Int | n < length l; n >= 0 } -> { -- notice the shortcutting,
-- using the l type as an argument to length instead
-- of having to bind l to a name as a foreach.
case (l, i) of -- similar shortcutting
(x:xs, 0) = x
(x:xs, n) = index xs (n - 1)
}