Skip to content

Instantly share code, notes, and snippets.

import math.*
import scipy.optimize.*
def k2t(k):
f = lambda t : gamma(1/t)*gamma(5/t)/gamma(3/t)**2-k-3
return fsolve(f,2)
@Odomontois
Odomontois / index.html
Created February 19, 2015 11:18 — forked from anonymous/index.html
Prettify bar
<input type='range' value='70' />

Revisiting Tagless Final Interpreters with Dotty

Tageless Final interpreters are an alternative to the traditional Algebraic Data Type (and generalized ADT) based implementation of the interpreter pattern. This document presents the Tageless Final approach with Scala, and shows how Dotty with it's recently added implicits functions makes the approach even more appealing. All examples are direct translations of their Haskell version presented in the Typed Tagless Final Interpreters: Lecture Notes (section 2).

The interpreter pattern has recently received a lot of attention in the Scala community. A lot of efforts have been invested in trying to address the biggest shortcomings of ADT/GADT based solutions: extensibility. One can first look at cats' Inject typeclass for an implementation of [Data Type à la Carte](http://www.cs.ru.nl/~W.Swierstra/Publications

@Odomontois
Odomontois / shapeless_tags_fun.scala
Created May 25, 2017 04:19 — forked from folex/shapeless_tags_fun.scala
shapeless_tags_fun.scala
import cats.data.Ior
object UserRelationsT {
import shapeless.tag
import tag.@@
import shapeless.Unwrapped
trait IsFollowerTag
type IsFollower = Boolean @@ IsFollowerTag
def isFollower(b: Boolean): IsFollower = tag[IsFollowerTag][Boolean](b)
@Odomontois
Odomontois / Session.scala
Created December 5, 2017 07:55 — forked from Tvaroh/Session.scala
Session Stream
import cats.{Monad, StackSafeMonad}
import cats.effect.{IO, LiftIO}
import io.iteratee.{Enumeratee, Enumerator, Iteratee}
import cats.implicits._
trait Session {
def close(): Unit
}
case class SessionContext[T](exec: Session => IO[T]) {
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
module Stepik () where
class (Enum a, Bounded a, Eq a) => SafeEnum a where
ssucc :: a -> a
ssucc x | x == maxBound = minBound
| otherwise = succ x
spred :: a -> a
@Odomontois
Odomontois / tagless-final-kv-store.scala
Last active August 7, 2018 15:01 — forked from igor-ramazanov/free-monads-kv-store.scala
An example how to compile a higher-level language into a lower-level one with parameterised argument types in Free monads way
package scalagroup
import cats.Functor
import cats.instances.function._
import cats.instances.string._
import cats.syntax.eq._
import cats.syntax.functor._
import simulacrum.typeclass
object KVStore {
def main(args: Array[String]): Unit = {
trait Iso[A, B] {
def to(a: A): B
def from(b: B): A
}
trait Derivable[F[_]] {
type Fields[_]
def fieldOf[A](name: String, value: F[A]): Fields[A]
def fieldUnit: Fields[Unit]
def fieldZip[A, B](left: Fields[A], right: Fields[B]): Fields[(A, B)]
@Odomontois
Odomontois / SmashProduct.ard
Last active August 12, 2020 06:31
Attempt to show that S1/\S1 = S2
\import Homotopy.Pointed
\data SmashProduct (X Y : Pointed)
| spd X Y -- "smash product data"
| smashl (x : X) (i : I) \elim i {
| left => spd x Y.base
| right => spd X.base Y.base
}
| smashr (y : Y) (i : I) \elim i {
| left => spd X.base y