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
// unfortunately | |
// opaque type Fix[F[_]] = F[Fix[F]] | |
// won't work (no recursion in opaque type), but this implementation is safe, but scary due to asInstanceOf | |
object FixImpl { | |
type Fix[F[_]] | |
inline def fix[F[_]](f: F[Fix[F]]): Fix[F] = f.asInstanceOf[Fix[F]] | |
inline def unfix[F[_]](f: Fix[F]): F[Fix[F]] = f.asInstanceOf[F[Fix[F]]] | |
} |
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
/* | |
* Consider a simple recursive function like: | |
* f(x) = if (x > 1) f(x - 1) + x | |
* else 0 | |
* | |
* This function isn't tail recursive (it could be, but let's set that aside for a moment). | |
* How can we mechanically, which is to say without thinking about it, convert this into a stack safe recursion? | |
* An approach is to model everything that happens after the recursion as a continuation, and build up that | |
* continuation in a stack safe manner. Here is some example code: | |
*/ |
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
[package] | |
name = "hello" | |
version = "0.1.0" | |
authors = ["P. Oscar Boykin <boykin@pobox.com>"] | |
edition = "2018" | |
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html | |
[dependencies] | |
csv = "1.1" |
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
/** | |
git clone https://github.com/twitter/scalding.git | |
cd scalding | |
./sbt scalding-repl/console | |
*/ | |
import scala.io.Source | |
val alice = Source.fromURL("http://www.gutenberg.org/files/11/11.txt").getLines | |
// Add the line numbers, which we might want later | |
val aliceLineNum = alice.zipWithIndex.toList |
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
/** | |
* To get started: | |
* git clone https://github.com/twitter/algebird | |
* cd algebird | |
* ./sbt algebird-core/console | |
*/ | |
/** | |
* Let's get some data. Here is Alice in Wonderland, line by line | |
*/ |
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
package org.bykn.refmap | |
import cats.data.State | |
import cats.effect.Sync | |
import cats.effect.concurrent.Ref | |
import java.util.concurrent.ConcurrentHashMap | |
import cats.implicits._ | |
/** |
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
package dev.posco.nui | |
import scala.compiletime.{erasedValue, error, ops, requireConst} | |
object NatExample { | |
sealed trait Nat | |
object Nat { | |
case object Zero extends Nat | |
case class Succ[N <: Nat](prev: N) extends Nat |
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 fs2.{Chunk, Stream, Pull} | |
import cats.collections.Heap | |
import cats.implicits._ | |
object SortMerge { | |
def sortMerge[F[_], A: Ordering](streams: List[Stream[F, A]]): Stream[F, A] = { | |
implicit val ord: cats.Order[Stream.StepLeg[F, A]] = | |
new cats.Order[Stream.StepLeg[F, A]] { | |
val ordA = implicitly[Ordering[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
// Run this with: scala Monad.scala | |
trait Monad[M[_]] { | |
// in haskell, called return, but that's a reserved word | |
// constructs a Monad instance from the given value, e.g. List(1) | |
def apply[T](v: T): M[T] | |
// flatMap function, in scala: | |
def bind[T,U](m: M[T])(fn: (T) => M[U]): M[U] | |
// Laws these must follow are: | |
// identities: |
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
#!/usr/bin/env python | |
import sys | |
# on osx you want brew install gnu-sed to get gsed | |
from sh import cp, rm, gsed, bazel, ErrorReturnCode | |
test_fn = lambda: bazel('build', sys.argv[1]) | |
filename = sys.argv[2] | |
print "Checking that tests pass before starting" | |
print test_fn() |
NewerOlder