Skip to content

Instantly share code, notes, and snippets.

View Baccata's full-sized avatar

Olivier Mélois Baccata

View GitHub Profile
module Main where
main = putStrLn (show (fforall (\x -> (x >= -1000)) (setInt)))
type Set a = a -> Bool
setInt :: Set Int
setInt = \x -> True
--filtering the range with the set function and checking if all elements from the set satisfy the predicate
fforall :: Restrict a => (a -> Bool) -> Set a -> Bool
@Baccata
Baccata / cloneAllBitbucket.sh
Last active July 1, 2016 12:40
Cloning all the repos under a user or team from bitbucket
#!/bin/bash
#Script to get all repositories under a user or team from bitbucket
#Usage: cloneAllBitbucket [username] [user_or_team]
curl -u ${1} https://api.bitbucket.org/1.0/users/${2} \
| jsawk 'return this.repositories.map(function(item){return item.name;})' \
| jsawk -n 'out(this)' \
| sed -e 's/^"//' -e 's/"$//' > repos
for repo_name in `cat repos`

Advanced Functional Programming with Scala - Notes

Copyright © 2017 Fantasyland Institute of Learning. All rights reserved.

1. Mastering Functions

A function is a mapping from one set, called a domain, to another set, called the codomain. A function associates every element in the domain with exactly one element in the codomain. In Scala, both domain and codomain are types.

val square : Int => Int = x => x * x
import cats.free.Free
import cats.{ Monad, ~> }
object KVStoreExample {
sealed trait KVStore[A]
case class Put[T](key: String, value: T) extends KVStore[Unit]
case class Get[T](key: String) extends KVStore[Option[T]]
object KVStore {
@Baccata
Baccata / ActorInterpreter.scala
Last active April 1, 2017 20:17
Transforming a pure stateful computation into an asynchronous effectful computation
import akka.actor.{ Actor, ActorSystem, Props }
import akka.util.Timeout
import cats._
import cats.data.State
class ActorInterpreter[G[_], StateData](
actorSystem: ActorSystem,
initialData: StateData,
stateInterpreter: G ~> Lambda[A => State[StateData, A]]
)(implicit t: Timeout, ec: ExecutionContext)
// *****************************************************************************
// Projects
// *****************************************************************************
lazy val `polykind-tests` =
project
.in(file("."))
.enablePlugins(AutomateHeaderPlugin, GitVersioning)
.settings(settings)
.settings(
@Baccata
Baccata / meeting.md
Created June 26, 2017 12:04 — forked from qingwei91/meeting.md
about meeting

Fantastic meetings and where to find them

Anecdotally most people in software industry hates meetings, because meeting is a soul-sucking dementor. Jokes aside, I think it's fair to say that people feel meeting is taking too much time, and the process is often painful.

In this post, I'll try to provide a few rules of thumb that I believe can make meeting less painful and more efficient.

Rule 1: Always reiterate your goal before start

How many times you attend a meeting without a goal in mind?

Explaining Miles's Magic

Miles Sabin recently opened a pull request fixing the infamous SI-2712. First off, this is remarkable and, if merged, will make everyone's life enormously easier. This is a bug that a lot of people hit often without even realizing it, and they just assume that either they did something wrong or the compiler is broken in some weird way. It is especially common for users of scalaz or cats.

But that's not what I wanted to write about. What I want to write about is the exact semantics of Miles's fix, because it does impose some very specific assumptions about the way that type constructors work, and understanding those assumptions is the key to getting the most of it his fix.

For starters, here is the sort of thing that SI-2712 affects:

def foo[F[_], A](fa: F[A]): String = fa.toString
@Baccata
Baccata / hylo.sc
Last active October 14, 2017 22:12
Stack safe hylomorphism using cats' lazy eval
// Look up ammonite if you're wondering what this syntax is
import $ivy.`org.typelevel::cats-core:1.0.0-MF`
import cats._
import cats.syntax.functor._
import cats.syntax.traverse._
sealed trait Nat[+A]
case object Zero extends Nat[Nothing]
case class Succ[A](a : A) extends Nat[A]
@Baccata
Baccata / Presentation.scala
Created November 20, 2017 10:03
Some toy examples of matryoshka use
package presentation
import matryoshka.data.Fix
import scalaz.Functor
object Presentation extends App {
// 1 : abstract recursion away