Skip to content

Instantly share code, notes, and snippets.

View hamishdickson's full-sized avatar
🥔
I like cake.

Hamish Dickson hamishdickson

🥔
I like cake.
View GitHub Profile
/*
* here is a cool thing @Astrac did
*
* lifts `A => F[B]` to `F[A => B]`, where `F` has a Comonad and an applicative
*/
def lift[F[_], A, B](f: A => F[B])(implicit cm: Comonad[F], ap: Applicative[F]): F[A => B] = ap.pure(a => f(a).extract)
@hamishdickson
hamishdickson / fib.scala
Created January 16, 2017 16:48
cofree impl of fib
final case class Cofree[F[_], A](head: A, tail: F[Cofree[F,A]])
val fibs: Cofree[Eval, Int] = {
def unfold(p1: Int, p2: Int): Cofree[Eval, Int] =
Cofree(p1 + p2, Eval.later(unfold(p2, p1 + p2)))
unfold(0, 1)
}
scala> fibs.head
@hamishdickson
hamishdickson / tagged.scala
Created January 10, 2017 14:00
Playing with tagged types and type classes in scala
[info] Loading global plugins from /Users/hamishdickson/.sbt/0.13/plugins
[info] Updating {file:/Users/hamishdickson/.sbt/0.13/plugins/}global-plugins...
[info] Resolving org.fusesource.jansi#jansi;1.4 ...
[info] Done updating.
[info] Set current project to catsSandbox (in build file:/Users/hamishdickson/Workspace/catsSandbox/)
[info] Starting scala interpreter...
[info]
Welcome to Scala 2.12.1 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_101).
Type in expressions for evaluation. Or try :help.
scala> trait Foo[T] {
| type A
| def woozle(a: T): A
| }
defined trait Foo
scala> implicit val bar = new Foo[Int] {
| type A = String
| def woozle(a: Int): A = s"hamish has had $a cakes today"
| }
scala> trait Foo[T] {
| type A
| def woozle(a: T): A
| }
defined trait Foo
scala> implicit val bar = new Foo[Int] {
| type A = String
| def woozle(a: Int): A = s"num: $a"
| }

SIP SLIP meeting October 2015

Welcomes and apologies

  • Welcome to @sjrd who joins us
  • @odersky, @jsuereth, @dickwall and @SethTisue are all there
  • @dickwall gloats about his holiday
  • @Eran has the flu
  • @heathermiller is "otherwise engaged"
@hamishdickson
hamishdickson / nlpintro.output
Last active October 20, 2015 20:45
nlpintro
$ ghci -XNoMonomorphismRestriction
GHCi, version 7.10.2: http://www.haskell.org/ghc/ :? for help
Prelude>
@hamishdickson
hamishdickson / test.java
Last active September 21, 2015 14:46
Calling a private method
public Test {
public void testMyThing() {
MyClass myClass = new MyClass();
Method method = myClass.getClass().getDeclaredMethod("setId", ArgTypeIfAny.class);
privateStringMethod.setAccessible(true);
method.invoke(myClass, args);
}
select(FruitTable.name, FruitTable.juiciness)
.from(FruitTable)
.where(FruitTable.juiciness >= 8)
.orderBy(FruitTable.juiciness.desc)
.fetchAll(fruitExtractor)
@hamishdickson
hamishdickson / DeleteExample.scala
Created January 31, 2015 15:40
For some reason this doesn't work...
object DeleteExamples extends App with DatabaseExample {
InsertExamples.insertAll
val deleteStatement =
delete
.from(FruitTable)
.where(FruitTable.name === """Banana""")
// try again to run the delete statement in a transaction
database.withTransaction {