Skip to content

Instantly share code, notes, and snippets.

Miles Sabin milessabin

Block or report user

Report or block milessabin

Hide content and notifications from this user.

Learn more about blocking users

Contact Support about this user’s behavior.

Learn more about reporting abuse

Report abuse
View GitHub Profile
@milessabin
milessabin / functork.scala
Created May 11, 2018
shapeless-style derivation of a FunctorK (aka HFunctor) instance for an arbitrary product F-algebra
View functork.scala
import scala.language.{ higherKinds, implicitConversions }
object Defns {
type Id[T] = T
type ApplyTo[T] = { type λ[F[_]] = F[T] }
type Const1[T] = { type λ[F[_]] = T }
// Natural transform
trait ~>[F[_], G[_]] {
def apply[T](ft: F[T]): G[T]
@milessabin
milessabin / no-effect.scala
Created Mar 20, 2018
Side-effects are bad, right?
View no-effect.scala
// What output does this yield? What should it? (try with either 2.12.x or 2.13.x)
// (spoiler: https://github.com/scala/bug/issues/10788)
object Test {
class Box[T](t: T) {
def foo: T = {
println("effect")
t
}
}
View proof.scala
import scala.language.higherKinds
class Cartesian[F[_]] {
trait Arbitrary1
trait Arbitrary2
implicit val fa1: F[Arbitrary1] = null.asInstanceOf
implicit val fa2: F[Arbitrary2] = null.asInstanceOf
class QED
implicit def proof(implicit fa12: F[(Arbitrary1, Arbitrary2)]): QED = null
}
@milessabin
milessabin / byname-inductive-implicits.scala
Created Sep 5, 2017
Compiles, no macros, induction heuristics applied ... on my scala/scala branch. Coming to a scalac near you soon with any luck ...
View byname-inductive-implicits.scala
@annotation.inductive
trait Show[T] {
def show(t: T): String
}
object Show {
implicit def showUnit: Show[Unit] = new Show[Unit] {
def show(u: Unit): String = "()"
}
@milessabin
milessabin / artifactory.config.latest.xml
Created Dec 3, 2016
My local artifactory configuration for community-builds
View artifactory.config.latest.xml
<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<config xmlns="http://artifactory.jfrog.org/xsd/1.8.1" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://www.jfrog.org/xsd/artifactory-v1_8_1.xsd">
<offlineMode>false</offlineMode>
<helpLinksEnabled>true</helpLinksEnabled>
<fileUploadMaxSizeMb>100</fileUploadMaxSizeMb>
<dateFormat>dd-MM-yy HH:mm:ss z</dateFormat>
<addons>
<showAddonsInfo>true</showAddonsInfo>
<showAddonsInfoCookie>1480700455180</showAddonsInfoCookie>
</addons>
View gist:2c5899806923569d322f81dc2241e65d
[acyclic] --== Extracting dependencies for acyclic ==--
[acyclic] Fetching https://github.com/lihaoyi/acyclic.git
[acyclic] into /home/miles/projects/community-builds/clones-0.9.5/245e354ad2399f7a8e44b501df16710d5ca8e18e-acyclic
[acyclic] Took: 00h 00m 00.4s
[acyclic] Cloning /home/miles/projects/community-builds/clones-0.9.5/245e354ad2399f7a8e44b501df16710d5ca8e18e-acyclic
[acyclic] to /home/miles/projects/community-builds/target-0.9.5/extraction/d4f22467376ec652fb03d6c58593ba6d267adf39/projects/73e1fbbb9c28dd54a52679838829b3b71d4f9386
[acyclic] Took: 00h 00m 00.0s
[acyclic] Fetching /home/miles/projects/community-builds/clones-0.9.5/245e354ad2399f7a8e44b501df16710d5ca8e18e-acyclic
[acyclic] into /home/miles/projects/community-builds/target-0.9.5/extraction/d4f22467376ec652fb03d6c58593ba6d267adf39/projects/73e1fbbb9c28dd54a52679838829b3b71d4f9386
[acyclic] Took: 00h 00m 00.0s
View gist:0ad6b15d2f750754c2bda565828eab14
miles@tarski:shapeless (master)% sbt -Dsbt.profile=2.12.x
[info] Loading global plugins from /home/miles/.sbt/0.13/plugins
[info] Loading project definition from /home/miles/projects/shapeless/project
[info] Set current project to root (in build file:/home/miles/projects/shapeless/)
> project coreJVM
[info] Set current project to core (in build file:/home/miles/projects/shapeless/)
> ++2.12.0-RC2
[info] Setting version to 2.12.0-RC2
[info] Reapplying settings...
[info] Set current project to core (in build file:/home/miles/projects/shapeless/)
@milessabin
milessabin / gist:c4b7285f40f7a1cc3593d93fa0ad3a02
Last active Oct 16, 2016
Intersecting both instances and syntax to resolve ambiguity
View gist:c4b7285f40f7a1cc3593d93fa0ad3a02
package demo
import scala.language.higherKinds
import scala.language.implicitConversions
trait Functor[F[_]] {
def map[A, B](fa: F[A])(f: A => B): F[B]
}
trait Monad[F[_]] extends Functor[F] {
View gist:1ed8da29f314df2942c2dfd5f5a573e6
import scala.language.higherKinds
trait Functor[F[_]] {
def map[A, B](fa: F[A])(f: A => B): F[B]
}
trait Traverse[F[_]] {
implicit val F: Functor[F]
}
View gist:b92b9bcc4298e0077ba033de49531bc0
tapply: (a -> b) -> a -> b
tapply ab a = ab a
foo: (tapply List Nat) --OK
foo = [1, 2, 3]
mkPair: a -> b -> (a, b)
mkPair a b = (a, b)
bar: (mkPair Nat String) -- Not OK
You can’t perform that action at this time.