Skip to content

Instantly share code, notes, and snippets.

View barambani's full-sized avatar

Filippo Mariotti barambani

View GitHub Profile
@barambani
barambani / basictex-install.sh
Created May 30, 2023 13:31 — forked from muzimuzhi/basictex-install.sh
install and config basicTeX
##
# A script to help you install and config basictex
# https://www.tug.org/mactex/morepackages.html
#
# References:
# - https://gist.github.com/kadrach/6228314
# - https://tex.stackexchange.com/a/304202
#
# Requirements:
# - homebrew
@barambani
barambani / install_xelatex_on_mac.txt
Created December 3, 2022 12:25 — forked from peterhurford/install_xelatex_on_mac.txt
How to install latex and xelatex on Mac so that Jupyter "Download as PDF" will work
brew install pandoc
brew tap homebrew/cask
brew install --cask basictex
eval "$(/usr/libexec/path_helper)"
# Update $PATH to include `/usr/local/texlive/2022basic/bin/universal-darwin`
sudo tlmgr update --self
sudo tlmgr install texliveonfly
sudo tlmgr install xelatex
sudo tlmgr install adjustbox
sudo tlmgr install tcolorbox
@barambani
barambani / listt.scala
Created January 9, 2019 21:31 — forked from tpolecat/listt.scala
A demonstration in Scala of failed associativity of ListT. Example taken from https://wiki.haskell.org/ListT_done_right
// addCompilerPlugin("com.milessabin" % "si2712fix-plugin" % "1.2.0" cross CrossVersion.full)
import scalaz._, Scalaz._
implicit def f2k[F[_], A, B](f: A => F[B]) = Kleisli(f)
val a: Int => ListT[List, Int] = {
case 0 => ListT(List(List(0, 1)))
case 1 => ListT(List(List(0), List(1)))
}
@barambani
barambani / GADTs.scala
Created December 1, 2018 15:22 — forked from pchiusano/GADTs.scala
GADT support in Scala
/** GADTs in Scala and their limitations */
/** Background: what is an algebraic data type (ADT) ?
* ADT: (possibly) recursive datatype with sums and products
* In scala - a trait with case classes (case class is product, subtyping is sum)
*/
/** Motivation: untyped embedded DSL doesn't prevent nonsensical expressions */
sealed trait Expr {
def apply(other: Expr) = Ap(this, other)
@barambani
barambani / fs2.scala
Created October 14, 2018 23:17 — forked from smarter/fs2.scala
trait Stream[+F[_], +A]
object Stream {
// Make scalac get over its oudenophobia.
type Nothing2[X] <: Nothing
def emits[F[x] >: Nothing2[x], A](as: List[A]): Stream[F, A] = new Stream[F, A] {}
implicit class InvariantOps[F[x] >: Nothing2[x], A](private val self: Stream[F, A]) extends AnyVal {
def ethrough[B](p: Stream[F, A] => Stream[F, B]): Stream[F, B] = p(self)
@barambani
barambani / LocalTests.scala
Created October 6, 2018 18:26 — forked from milessabin/LocalTests.scala
Setup for local integration (ie. compile pos/neg/run) tests for lampepfl/dotty
// local/localtests/test/localtests/LocalTests.scala
package localtests
import java.nio.file._
import java.util.stream.{ Stream => JStream }
import org.junit.{ AfterClass, Test }
import scala.collection.JavaConverters._
import scala.concurrent.duration._
@barambani
barambani / typelevelcps.scala
Created August 27, 2018 12:45 — forked from milessabin/typelevelcps.scala
Using type level continuation passing style to rewrite a whitebox macro (which relies on fundep materialization) as a blackbox macro
import scala.language.higherKinds
// Whitebox ...
trait Schema[T, R] {
def conv(t: T): R
}
object Schema {
// Whitebox macro: R is computed from T
implicit def mkSchema[T, R]: Schema[T, R] = ??? // macro ...
@barambani
barambani / fpmax.scala
Created July 15, 2018 13:29 — forked from jdegoes/fpmax.scala
FP to the Max — Code Examples
package fpmax
import scala.util.Try
import scala.io.StdIn.readLine
object App0 {
def main: Unit = {
println("What is your name?")
val name = readLine()
@barambani
barambani / kinds.md
Created June 11, 2018 15:05 — forked from 5310/kinds.md
Kind Polymorphism in Haskell #article

So we have all these types like Int, Float, String, Map String Int, [Maybe String], etc. What do all these types have in common? Well, essentially, they're "normal" types where we can make a value for them. Just as values have types, types have "kinds". In this case, just as 4 : Int, Int : *, and just as "Hello" : String, String : *. That is to say, all these normal types (the types of plain old values) have kind *.

Now, in OCaml, you have type parametricity, but only over types of kind *. Let's give an example of a type that's not of kind *.

Map : * -> * -> *

We apply this "type constructor" (which is a kind of "type function", just like constructors are a kind of function) to the type Int : *.

Map Int : * -> *

Advanced Functional Programming with Scala - Notes

Copyright © 2016-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