This file contains hidden or 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
| #! /usr/bin/env nix-shell | |
| #! nix-shell -i 'runhaskell --ghc-arg=-threaded' | |
| #! nix-shell -p 'ghc.withPackages (p: with p; [ turtle text hnix ])' | |
| #! nix-shell -p coursier nix | |
| #! nix-shell --pure | |
| {-# LANGUAGE OverloadedStrings #-} | |
| {-# LANGUAGE TupleSections #-} | |
| import qualified Control.Foldl as Foldl |
This file contains hidden or 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 Monoid[A] { | |
| def zero: A | |
| def op(lhs: A, rhs: A): A | |
| } | |
| def listMonoid[A]: Monoid[List[A]] = new Monoid[List[A]] { | |
| override def zero: List[A] = List() | |
| override def op(lhs: List[A], rhs: List[A]): List[A] = |
This file contains hidden or 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
| // for ammonite | |
| // import $ivy.`com.chuusai::shapeless:2.3.2` | |
| import shapeless._ | |
| import shapeless.labelled._ | |
| import shapeless.ops.hlist._ | |
| import shapeless.ops.record._ | |
| case class IceCream(flavour: String, price: Int) |
This file contains hidden or 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
| # Nix file for DoorKickers | |
| # | |
| # - make sure 'DoorKickers.tar.gz' is in the same dir | |
| # - run: | |
| # $ nix-build -E 'with import <nixpkgs> { }; callPackage_i686 ./default.nix { }' | |
| {lib, openal, glibc, libGL, libX11, libogg, xorg, makeWrapper, stdenv }: | |
| stdenv.mkDerivation { | |
| name = "DoorKickers"; | |
| src = ./DoorKickers.tar.gz; |
This file contains hidden or 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
| { pkgs ? import <nixpkgs> {}}: | |
| with pkgs; | |
| let | |
| writePureScriptBin = { name, deps ? [], interp ? stdenv.shell }: text: | |
| writeScriptBin name '' | |
| #!${interp} | |
| export PATH=${lib.makeBinPath deps} |
This file contains hidden or 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
| // source: https://gist.github.com/markus1189/760d1078b462c282ab44 | |
| /* Example of using phantom types to make a type safe builder. | |
| * A House requires: | |
| * - a roof which can be either flat or normal | |
| * - a base, after one set this can never be removed again and neither added again | |
| * - side walls, can be removed/added if (not) present | |
| * - a door, can be removed/added if (not) present | |
| * | |
| * the `build` method can only be called if the builder is in a valid | |
| * state and will create the correct result type, e.g. a flat house or |
This file contains hidden or 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
| {-# LANGUAGE GADTs #-} | |
| {-# LANGUAGE TypeFamilies #-} | |
| {-# LANGUAGE DataKinds #-} | |
| module LightSwitch where | |
| data Power = On | Off | |
| type family Toggle (a :: Power) where | |
| Toggle On = Off | |
| Toggle Off = On |
This file contains hidden or 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
| sealed abstract class Power | |
| final abstract class On extends Power | |
| final abstract class Off extends Power | |
| class LightSwitch[State <: Power] private { | |
| def on(implicit ev: State =:= Off) = LightSwitch.on | |
| def off(implicit ev: State =:= On) = LightSwitch.off | |
| def toggleP[S<:Power](implicit t: ToggleP[State,S]): LightSwitch[S] = new LightSwitch[S] | |
| def toggleM[S<:Power](implicit t: ToggleM.Aux[State,S]): LightSwitch[S] = | |
| new LightSwitch[S] |
This file contains hidden or 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
| sealed trait Power | |
| trait On extends Power | |
| trait Off extends Power | |
| class LightSwitch[State <: Power] private { | |
| def on(implicit ev: State =:= Off) = new LightSwitch[On] | |
| def off(implicit ev: State =:= On) = new LightSwitch[Off] | |
| def toggle[S<:Power](implicit t: Toggle.Aux[State,S]): LightSwitch[S] = new LightSwitch[S] | |
| } |
This file contains hidden or 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
| sealed trait Power { type Toggle <: Power } | |
| trait On extends Power { type Toggle = Off } | |
| trait Off extends Power { type Toggle = On } | |
| class LightSwitch[State <: Power] private { | |
| def on(implicit ev: State =:= Off) = new LightSwitch[On] | |
| def off(implicit ev: State =:= On) = new LightSwitch[Off] | |
| def toggle = new LightSwitch[State#Toggle] | |
| } |