Skip to content

Instantly share code, notes, and snippets.

View jpablo's full-sized avatar

juan pablo romero jpablo

View GitHub Profile
//> using scala "3.2"
//> using lib "dev.zio::zio-json:0.3.0"
import zio.json.*
import zio.json.ast.Json
type T1 = (String, Int)
type T2 = (Int, String)
given JsonDecoder[T1 | T2] =
import tactic.basic
import category_theory.category
open category_theory
universes u v
variables {C : Type u} [category.{v} C] {X Y Z : C}
structure are_isomorph (X Y: C) :=
@jpablo
jpablo / build.sbt
Last active November 16, 2020 14:15
Using discipline to test Category laws
val dottyVersion = "0.20.0-RC1"
lazy val root = project
.in(file("."))
.settings(
name := "discipline-example",
version := "0.1.0",
libraryDependencies ++= Seq(
"com.novocode" % "junit-interface" % "0.11" % "test",
("org.typelevel" % "cats-core_2.13" % "2.0.0").withDottyCompat(scalaVersion.value),
@jpablo
jpablo / credentials.sc
Last active December 10, 2018 07:54
Twitter to csv
object creds {
val consumer_key = ""
val consumer_secret = ""
val access_token = ""
val access_secret = ""
}
@jpablo
jpablo / Estado.hs
Last active April 18, 2017 06:50
State instances: Functor, Applicative, Monad
{-# LANGUAGE InstanceSigs #-}
module State where
import Control.Monad
data Estado s a = Estado { corre :: s -> (a, s) }
instance Functor (Estado s) where
@jpablo
jpablo / picture-language.hs
Last active March 30, 2017 05:20
picture language exercises
module Chap2.PictureLanguage where
-- data Painter
-- 2.2.4 Example: A Picture Language
beside :: a -> a -> a
beside a b = undefined
below :: a -> a -> a
below bottom top = undefined
@jpablo
jpablo / DataAbstraction.scala
Created December 8, 2016 09:48
SICP 2.1.1: Data Abstraction
package Chap2
import scala.language.higherKinds
trait AbstractTypes {
type Rational[A]
def makeRat[A](x: A, y: A): Rational[A]
@jpablo
jpablo / Safe and subtyping.scala
Last active November 26, 2016 09:31
It is only safe to forget
def Environment[A, X](x: X) = {
val a: A = x
// this is safe iff X <: A
// in other words, if we discard information
// (otherwise we might try to use `a` in an operation it doesn't support)
// in other words: it is only safe to forget information
// another form:
def f(a: A) = {
@jpablo
jpablo / primes.hs
Last active November 24, 2016 18:01
IO Monad, Random numbers in Haskell
-- required: stack install random
import System.Random
-------- Fermat test -----------------
expmod base e m
| e == 0 = 1
| even e = mod (expmod base (e `div` 2) m ^ 2) m
| otherwise = mod (base * expmod base (e - 1) m) m
@jpablo
jpablo / ObjectAlgebras.ts
Last active July 18, 2020 21:33
Extensibility for the masses, typescript:
// Initial object algebra interface for expressions: integers and addition
interface ExpAlg<E> {
lit(x: number): E
add(e1: E, e2: E): E
}
// The evaluation interface
interface Eval {
eval(): number
}