Skip to content

Instantly share code, notes, and snippets.

View debasishg's full-sized avatar
🏠
Working from home

Debasish Ghosh debasishg

🏠
Working from home
View GitHub Profile
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
@debasishg
debasishg / Haskell
Created November 3, 2017 16:36 — forked from anonymous/Haskell
Comparison of the straightforward embedding of a basic tenet of category theory in Scala vs Haskell.
yonedaLemma = Iso (flip fmap) ($ id)
@debasishg
debasishg / type-inhabitants.markdown
Created October 26, 2017 07:29 — forked from pchiusano/type-inhabitants.markdown
Reasoning about type inhabitants in Haskell

This is material to go along with a 2014 Boston Haskell talk.

We are going to look at a series of type signatures in Haskell and explore how parametricity (or lack thereof) lets us constrain what a function is allowed to do.

Let's start with a decidedly non-generic function signature. What are the possible implementations of this function which typecheck?

wrangle :: Int -> Int
@debasishg
debasishg / gist:f473167ac91b2af4949c6340d4aa0c1b
Created August 12, 2017 21:49 — forked from runarorama/gist:78c8fefbab74701afab3
Playing around with "Finally Tagless, Partially Evaluated" in Scala
// Finally tagless lambda calculus
object Final {
def varZ[A,B](env1: A, env2: B): A = env1
def varS[A,B,T](vp: B => T)(env1: A, env2: B): T = vp(env2)
def b[E](bv: Boolean)(env: E): Boolean = bv
def lam[A,E,T](e: (A, E) => T)(env: E): A => T = x => e(x, env)
def app[A,E,T](e1: E => A => T, e2: E => A)(env: E): T = e1(env)(e2(env))
def testf1[E,A](env: E): Boolean =
app(lam[Boolean,E,Boolean](varZ) _, b(true))(env)
@debasishg
debasishg / build.sbt
Created July 28, 2017 19:28 — forked from lamdor/build.sbt
Playing around with tagless final style and Eff (from https://github.com/edmundnoble/final-tagless-typelevel-summit)
scalaVersion := "2.11.8"
scalaOrganization := "org.typelevel"
libraryDependencies ++= Seq(
"org.typelevel" %% "cats" % "0.9.0",
"org.atnos" %% "eff" % "4.0.0"
)
addCompilerPlugin("org.spire-math" %% "kind-projector" % "0.9.3")
@debasishg
debasishg / exclude_targetdirs.sh
Created January 21, 2017 18:49 — forked from viktorklang/exclude_targetdirs.sh
Adds all your sbt target dirs as path excludes for Time Machine
#WARNING: Use at your own risk. No warranties expressed or implied. YMMV. Drive responsibly. Eat healthy.
#First, `cd` into the parent dir for all of your `sbt`/`maven` projects (I assume you have one of those)
find "$(cd ..; pwd)" -type d -name "target" -exec sudo tmutil addexclusion -p {} +
@debasishg
debasishg / Task.scala
Created January 6, 2016 06:24 — forked from shajra/Task.scala
integration code between Scalaz and Scala standard concurrency libraries.
import concurrent.{ExecutionContext, Future => SFuture, Promise}
import util.Try
import _root_.scalaz.\/
import _root_.scalaz.concurrent.{Task => ZTask}
object Task {
def fromScala[A]
14:26 ~/Projects/210x (2.10.x)$ scala
Welcome to Scala version 2.10.1-20130204-105326-3d318be51f (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_37).
Type in expressions to have them evaluated.
Type :help for more information.
scala> case class Shop(store: String, item: String, cost: Int) { def this() = this(null, null, 0) }
defined class Shop
scala> val t = typeOf[Shop]
t: reflect.runtime.universe.Type = Shop
import scala.reflect.runtime.universe._
import scala.reflect.api.{TypeCreator, Universe}
object Test extends App {
def foo[T: TypeTag] = TypeTag(typeTag[T].mirror, new TypeCreator {
override def apply[U <: Universe with Singleton](m: scala.reflect.api.Mirror[U]): U # Type = {
typeTag[T].in(m).tpe match {
case TypeRef(_, _, argHead :: Nil) => argHead.asInstanceOf[U#Type]
}
}
@debasishg
debasishg / gist:4698878
Last active December 12, 2015 02:28 — forked from dcsobral/gist:4698349
// At the external API level, use TypeTag
def extract[T: TypeTag](jsv: JsValue): T =
extractImpl[T](jsv, typeOf[T])
// But use Type for everything else
def extractImpl[T](jsv: JsValue, tpe: Type): T = {
// no need for m
val ex = jsv match {
case JsNumber(n) => n
case JsString(s) => s