Skip to content

Instantly share code, notes, and snippets.

View drdozer's full-sized avatar

Matthew Pocock drdozer

  • Newcastle upon Tyne, England
View GitHub Profile
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
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
@drdozer
drdozer / Main.scala
Created January 21, 2019 19:23
extension methods visibility
object Main {
implicit object Foo {
def (i: Int) eyes: String = "x" * i
}
trait Bar {
def (i: Int) nose: String
}
import scala.language.higherKinds
trait LogDSL[L]
object LogDSL {
implicit object LogRecsLogDSL extends LogDSL[String]
def runLog(ls: String): String = ???
}
trait Direction[D] {
@drdozer
drdozer / TurtlesQ.scala
Last active April 3, 2017 23:51
A queue with an inner queue to stage appends
sealed trait TurtlesQ[A] {
import TurtlesQ._
// fixme: size is being calculated incorrecty for append nodes
def size: Int
def conswise: TurtlesQ[A]
// 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
@drdozer
drdozer / blast.sc
Created March 16, 2017 11:04
example of calling blast from ammonite
/// ceremony begins
import ammonite.ops._
import ammonite.ops.ImplicitWd._
import scala.util.Random
/// now we can write our script
@drdozer
drdozer / it didn't happen
Last active March 1, 2017 17:53
Working with simple multiple trial probabilities
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
@drdozer
drdozer / telomereMutate.sc
Created March 1, 2017 01:08
little scala amm script to generate and then mutate perfect telomeric repeats
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
import cats.Id
import cats.data.{Const, Prod}
/**
*
*
* @author Matthew Pocock
*/
object TestImplicitProblem {
def main(args: Array[String]): Unit = {