type StringBool = "true"|"false";
interface AnyNumber { prev?: any, isZero: StringBool };
interface PositiveNumber { prev: any, isZero: "false" };
type IsZero<TNumber extends AnyNumber> = TNumber["isZero"];
type Next<TNumber extends AnyNumber> = { prev: TNumber, isZero: "false" };
type Prev<TNumber extends PositiveNumber> = TNumber["prev"];
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- a continuation of https://gist.github.com/gelisam/137effb33d2777328d366dcb563d8d13 | |
{-# LANGUAGE FlexibleContexts, FlexibleInstances, GeneralizedNewtypeDeriving, LambdaCase, MultiParamTypeClasses #-} | |
module EIO where | |
import Control.Monad | |
import Data.Void | |
import Test.DocTest | |
import qualified Control.Exception as E | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// This example shows how higher-kinded types can be emulated in Swift today. | |
// It acheives correct typing at the cost of some boilerplate, manual lifting and an existential representation. | |
// The technique below was directly inspired by the paper Lightweight Higher-Kinded Polymorphism | |
// by Jeremy Yallop and Leo White found at http://ocamllabs.io/higher/lightweight-higher-kinded-polymorphism.pdf | |
/// `ConstructorTag` represents a type constructor. | |
/// `Argument` represents an argument to the type constructor. | |
struct Apply<ConstructorTag, Argument> { | |
/// An existential containing a value of `Constructor<Argument>` | |
/// Where `Constructor` is the type constructor represented by `ConstructorTag` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
trait Higher<A, B> { | |
type Target; | |
} | |
trait Higher3<A, B, C> { | |
type Target2; | |
type Target3; | |
} | |
impl<A, B> Higher<A, B> for Option<A> { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- Example usage | |
module Main where | |
import Union | |
unionValue1 :: Union (String, (Double, ((Int, Int), ()))) | |
unionValue1 = mkUnion "Foo" | |
unionValue2 :: Union (String, (Double, ((Int, Int), ()))) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
-- in reply to http://www.reddit.com/r/haskell/comments/21mja6/make_lllegal_state_transitions_unrepresentable/ | |
-- | |
-- We implement a tiny language with three commands: Open, Close, and Get. | |
-- The first Get after an Open returns 1, the second Get returns 2, and so on. | |
-- | |
-- Get is only valid while the state is open, and | |
-- Open must always be matched by a Close. | |
-- We enforce both restrictions via the type system. | |
-- | |
-- There are two valid states: Opened and Closed. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { log } from 'fp-ts/lib/Console' | |
import { none, Option, some } from 'fp-ts/lib/Option' | |
import { randomInt } from 'fp-ts/lib/Random' | |
import { fromIO, Task, task } from 'fp-ts/lib/Task' | |
import { createInterface } from 'readline' | |
// | |
// helpers | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { SFC } from 'react'; | |
import { MapDispatchToPropsParam, MapStateToPropsParam } from 'react-redux'; | |
import { StateRoot } from 'reducers/types'; | |
import { AnyAction, Dispatch } from 'redux'; | |
// | |
// Helpers | |
// | |
const createSubType = <T extends any>() => <SubType extends T>(subType: SubType) => subType; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import { log } from 'fp-ts/lib/Console' | |
import { Type, URIS } from 'fp-ts/lib/HKT' | |
import { none, Option, some } from 'fp-ts/lib/Option' | |
import { randomInt } from 'fp-ts/lib/Random' | |
import { fromIO, Task, task, URI as TaskURI } from 'fp-ts/lib/Task' | |
import { createInterface } from 'readline' | |
// | |
// helpers | |
// |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
gstash() { | |
local out k reflog | |
out=( | |
$(git stash list --pretty='%C(yellow)%gd %>(14)%Cgreen%cr %C(blue)%gs' | | |
fzf --ansi --no-sort --header='enter:show, ctrl-d:diff, ctrl-o:pop, ctrl-y:apply, ctrl-x:drop' \ | |
--preview='git stash show --color=always -p $(cut -d" " -f1 <<< {}) | head -'$LINES \ | |
--preview-window=down:50% --reverse \ | |
--bind='enter:execute(git stash show --color=always -p $(cut -d" " -f1 <<< {}) | less -r > /dev/tty)' \ | |
--bind='ctrl-d:execute(git diff --color=always $(cut -d" " -f1 <<< {}) | less -r > /dev/tty)' \ | |
--expect=ctrl-o,ctrl-y,ctrl-x)) |