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
scala> def foo[T, Coll[T] <: Seq[T]] = ??? | |
warning: there were 1 feature warning(s); re-run with -feature for details | |
foo: [T, Coll[T] <: Seq[T]]=> Nothing | |
scala> foo[Int, List[Int]] | |
<console>:9: error: List[Int] takes no type parameters, expected: one | |
foo[Int, List[Int]] | |
^ | |
scala> type LA[A] = List[Int] | |
defined type alias LA |
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 Functor { | |
type M <: { type T } | |
def fmap[A, B](fa: M { type T = A })(f: A => B): M { type T = B } | |
} | |
implicit class EitherRightFunctor extends Functor { self => | |
type L | |
type M = Either { type A = self.L ; type T = B } //doesn't this specify a subtype of Either, rather than Either itself? | |
def fmap[A0, B0](fa: M { type A = self.L ; type B = A0 })(f: A0 => B0): Either { type A = self.L ; type B = B0 } = |
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
implicit class MaxBy[A](t: (A, A)) { | |
def maxBy[B: Order](f: A => B) = | |
(Order[A].order _).tupled(t umap f) match { | |
case GT | EQ => t._1 | |
case LT => t._2 | |
} | |
} |
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 Monad[M[_]] { | |
def pure[A](a: A): M[A] | |
def flatMap[A, B](f: A => M[B]): M[A] => M[B] | |
def map[A, B](f: A => B): M[A] => M[B] = flatMap(a => pure(f(a))) | |
} | |
class EitherRightMonad[L] extends Monad[({type M[R] = Either[L, R]})#M] { | |
def pure[A](a: A): Either[L, A] = error("todo") | |
def flatMap[A, B](f: A => Either[L, B]): Either[L, A] => Either[L, B] = error("todo") | |
} |
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
cabal install --only-dependencies | grep reinstall 1 ↵ | |
unix-2.7.0.1 (reinstall) changes: bytestring-0.10.4.0 -> 0.10.2.0 | |
directory-1.2.1.0 (reinstall) | |
process-1.2.0.0 (reinstall) | |
cabal: The following packages are likely to be broken by the reinstalls: | |
haskell98-2.0.0.3 | |
ghc-7.8.3 | |
Cabal-1.18.1.4 | |
bin-package-db-0.0.0.0 | |
haskeline-0.7.1.2 |
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
object Foo { | |
def unapply(a: ASup): Option[B] = | |
a match { | |
case a0: A => a0.b match { case b: B => Some(b); case _ => None } | |
case _ => None | |
} | |
} | |
ax collect { case Foo(b) => ... } |
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
{-# LANGUAGE RankNTypes #-} | |
module ListAlgebra | |
( ListAlgebra(..) | |
) where | |
newtype ListAlgebra a = ListAlgebra (forall b. b -> (a -> b -> b) -> b) | |
nil :: ListAlgebra a | |
nil = ListAlgebra const |
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
➜ quixotic git:(master) ✗ nix-shell --arg networkBitcoin 'import /home/nuttycom/oss/network-bitcoin {}' | |
[nix-shell:~/projects/quixotic]$ eval "$configurePhase" | |
configure flags: --enable-split-objs --disable-library-profiling --enable-shared --enable-library-vanilla --enable-executable-dynamic --enable-tests --ghc-option=-optl=-Wl,-rpath=/nix/store/jg1r4ghgyc97y84dnridx0wx4pq98g14-haskell-quixotic-ghc7.8.4-0.1-shared/lib/ghc-7.8.4/quixotic-0.1 | |
Warning: quixotic.cabal: This package requires at least Cabal version 1.20 | |
Configuring quixotic-0.1... | |
Setup: At least the following dependencies are missing: | |
configurator ==0.2.*, optparse-applicative >=0.9.0 && <0.10 | |
[nix-shell:~/projects/quixotic]$ cat shell.nix | |
# This file was auto-generated by cabal2nix. Please do NOT edit manually! |
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
require 'flow/common/function' | |
class Maybe | |
include Enumerable | |
def self.just(v) | |
Maybe.new(->(if_nothing, if_just) { if_just.call(v) }) | |
end | |
def self.nothing |