Skip to content

Instantly share code, notes, and snippets.

View tpolecat's full-sized avatar
🔥
Dijkstra would not have liked this.

Rob Norris tpolecat

🔥
Dijkstra would not have liked this.
View GitHub Profile
lambda = Lpr + 6.288750 * sin(Mpr)
+ 1.274018 * sin(2*D - Mpr)
+ 0.658309 * sin(2*D)
+ 0.213616 * sin(2*Mpr)
- e * 0.185596 * sin(M)
- 0.114336 * sin(2*F)
+ 0.058793 * sin(2*D - 2*Mpr)
+ e * 0.057212 * sin(2*D - M - Mpr)
+ 0.053320 * sin(2*D + Mpr)
+ e * 0.045874 * sin(2*D - M)
object Ishi extends App {
class Primes {
val primes: Stream[Long] = 2 #:: primesStartingFrom(3)
def isPrime(n: Long): Boolean = {
val limit = math.sqrt(n).ceil.toInt
!primes.takeWhile(_ < limit).exists(n % _ == 0)
}
trait T[A]
trait Bar[A] {
implicit def T: T[A]
}
trait Foo[A] extends Bar[A]
class Cake[A: T](a: A) extends Foo[A] {
def T: T[A] = implicitly
public class MyJavaClass {
protected int bar = 1;
}
trait MyScalaTrait extends MyJavaClass {
def foo = {
bar = bar + 1
bar
}
import language.higherKinds
object FooExample extends App {
// Slice of comonad is where this came up
trait Foo[F[_]] {
def coflatMap[A, B](f: F[A] => B): F[A] => F[B]
}
// A non-empty list
object stuff {
import scala.util.parsing.combinator._
class Parser extends RegexParsers {
def parseTop(s: String): Stuff = parse(top(""), s) match {
case Success(value, _) => value
case _ => throw new RuntimeException("...")
}
implicit def mv[F] = new Monad[({ type λ[a] = Validation[F, a] })#λ] {
def bind[A, B](fa: Validation[F, A])(f: A => Validation[F, B]): Validation[F, B] = fa.flatMap(f)
def point[A](a: => A): Validation[F, A] = a.success
}
object Nafg {
object Tuples {
trait HT[A] {
type H
type T
def hd(a: A): H
def tl(a: A): T
}
object Tuples {
trait HT {
type H
type T
def hd: H
def tl: T
}
implicit class T3[A, B, C](t: (A, B, C)) extends HT {
import annotation.implicitNotFound
@implicitNotFound(msg = "This message can never appear!")
trait ~>[A, B] { self =>
def apply(a: A): B
def invert(b: B): A = inverse.apply(b)
def inverse: B ~> A = new ~>[B, A] {
def apply(b: B) = self.invert(b)
override def invert(a: A) = self(a)
}