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 SemiRng[S] { | |
def add(lhs: S, rhs: S): S | |
def mult(lhs: S, rhs: S): S | |
} | |
object SemiRng { | |
opaque type Add[S] = S | |
object Add { | |
def apply[S](s: S): Add[S] = s | |
def (a: Add[S]) unwrap[S]: S = 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
import scala.language.higherKinds | |
// log into a trie data structure | |
trait LogDSL[L] { | |
def (message: String) log: L | |
} | |
object LogDSL { | |
implicit object LogRecsLogDSL extends LogDSL[String] { | |
def (message: String) log = message |
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 Main { | |
implicit object Foo { | |
def (i: Int) eyes: String = "x" * i | |
} | |
trait Bar { | |
def (i: Int) nose: String | |
} |
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 scala.language.higherKinds | |
trait LogDSL[L] | |
object LogDSL { | |
implicit object LogRecsLogDSL extends LogDSL[String] | |
def runLog(ls: String): String = ??? | |
} | |
trait Direction[D] { |
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
sealed trait TurtlesQ[A] { | |
import TurtlesQ._ | |
// fixme: size is being calculated incorrecty for append nodes | |
def size: Int | |
def conswise: TurtlesQ[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
// todo: these data structures expect lists to be non-empty but I've not bothered encoding this | |
// each non-empty list could be modelled by pulling the head directly into the case class, and having | |
// a possibly empty tail, but life is short | |
sealed trait OkasakiAppendableQueue[A] { | |
def :+ (a: A): OkasakiAppendableQueue[A] | |
def +: (a: A): OkasakiAppendableQueue[A] | |
def headTail: Option[(A, OkasakiAppendableQueue[A])] | |
def initsLast: Option[(OkasakiAppendableQueue[A], A)] | |
def isEmpty: Boolean |
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
/// ceremony begins | |
import ammonite.ops._ | |
import ammonite.ops.ImplicitWd._ | |
import scala.util.Random | |
/// now we can write our script |
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
The question we're answering here is how many times we need to try something | |
to have some level of certainty that it will happen at least once. | |
For example, if a parent has children, each with independent mutations, | |
how many children are needed until the chances of at least one of those children carrying a particular mutation exceeds 90%. | |
First some notation. | |
p(e) :: probability of some event e happening in a single trial | |
p(¬e) :: probability that some event e does not happen |
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 scala.util.Random | |
val DNA = "AGCT" | |
val telRep = "TTAGG" | |
val startCodon = "ATG" | |
val stopCodons = Set("TAG", "TAA", "TGA") | |
def telSeq(reps: Int) = telRep * reps |
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 cats.Id | |
import cats.data.{Const, Prod} | |
/** | |
* | |
* | |
* @author Matthew Pocock | |
*/ | |
object TestImplicitProblem { | |
def main(args: Array[String]): Unit = { |
NewerOlder