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
| import scalaprops._ | |
| /** Generate a permutation of the given values. | |
| * | |
| * > permute("ABC").sample | |
| * Vector(A,C,B) | |
| * > permute("ABC").sample | |
| * Vector(B,A,C) | |
| */ | |
| def permute[A](values: IndexedSeq[A]): Gen[IndexedSeq[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
| object Test extends App { | |
| // From https://stackoverflow.com/a/6944070 | |
| trait =!=[A, B] | |
| implicit def neq[A, B] : A =!= B = null | |
| // This pair excludes the A =:= B case | |
| implicit def neqAmbig1[A] : A =!= A = null |
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
| TARGET=. | |
| REPORT=/tmp/foo.sha | |
| find $TARGET -type f -print0 | sort -z | xargs -0 sha1sum | tee >(sha1sum >> $REPORT) > $REPORT |
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
| module Main | |
| data Nt : Type where | |
| Zn : Nt | |
| Sn : Nt -> Nt | |
| mutual | |
| data Even : Nt -> Type where | |
| EvenZn : Even Zn | |
| EvenSn : Odd n -> Even (Sn n) |
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
| sqlite> create table foo ( id int not null ); | |
| sqlite> insert into foo values (1); | |
| sqlite> insert into foo values (2); | |
| sqlite> insert into foo values ("hello"); | |
| sqlite> select * from foo; | |
| 1 | |
| 2 | |
| hello |
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
| module Set where | |
| import Data.Set (Set) | |
| import qualified Data.Set as S | |
| -- | Compare two 'Set's by inclusion or, failing that, by size. | |
| compareInclusion :: (Ord e) => Set e -> Set e -> Ordering | |
| compareInclusion s1 s2 = | |
| let lt = S.isSubsetOf s1 s2 | |
| gt = S.isSubsetOf s2 s1 |
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
| Copyright Thomas Sutton (c) 2015 | |
| All rights reserved. | |
| Redistribution and use in source and binary forms, with or without | |
| modification, are permitted provided that the following conditions are met: | |
| * Redistributions of source code must retain the above copyright | |
| notice, this list of conditions and the following disclaimer. |
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 Validation[T] { | |
| def must(p: (T => Boolean), error: String): Validation[T] | |
| } | |
| object Validation { | |
| def apply[T](value: T): Validation[T] = Valid(value) | |
| } | |
| case class Invalid[T](value: T, errors: List[String]) extends Validation[T] { | |
| def must(p: (T => Boolean), error: String): Validation[T] = |
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 DataKinds #-} | |
| {-# LANGUAGE KindSignatures #-} | |
| {-# LANGUAGE MultiParamTypeClasses #-} | |
| module Foo where | |
| import GHC.TypeLits | |
| data Header (sym :: Symbol) (val :: Symbol) | |
| type Foo = '[Header "X-Forwarded-For" "Satan"] |
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
| module Main where | |
| import System.Exit | |
| import System.Process | |
| main :: IO () | |
| main = do | |
| (c1, o1, e1) <- readProcessWithExitCode "ghc" ["-ilib", "-o", "/tmp/failure", "test/fail.hs"] "" | |
| (c2, o2, e2) <- readProcessWithExitCode "ghc" ["-ilib", "-o", "/tmp/passure", "test/pass.hs"] "" |