Skip to content

Instantly share code, notes, and snippets.

View folone's full-sized avatar
🏔️

George Leontiev folone

🏔️
View GitHub Profile
@folone
folone / gist:5320098
Last active December 15, 2015 20:40
Fooling around with State, defined as a monad of Adjunction[Writer, Reader], as per http://stackoverflow.com/a/4702513/163423
> core/console
[warn] Credentials file /home/folone/.ivy2/.credentials does not exist
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.9.2 (OpenJDK 64-Bit Server VM, Java 1.7.0_17).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scalaz._
import scalaz._
@folone
folone / kind.scala
Last active December 15, 2015 12:39
:kind in scala repl (work in progress)
BUILD SUCCESSFUL
Total time: 9 minutes 21 seconds
Welcome to Scala version 2.11.0-20130329-204437-40d2981c24 (OpenJDK 64-Bit Server VM, Java 1.7.0_17).
Type in expressions to have them evaluated.
Type :help for more information.
scala> :kind scala.Option
Option's kind is * -> *
scala> :k scalaz.Unapply
@folone
folone / kind.scala
Last active February 20, 2018 22:18 — forked from eed3si9n/kind.scala
// Updated for Scala 2.10.0.
def kind[A: scala.reflect.runtime.universe.TypeTag](a: A): String = {
import scala.reflect.runtime.universe._
def typeKind(sig: Type): String = sig match {
case PolyType(params, resultType) =>
(params map { p =>
typeKind(p.typeSignature) match {
case "*" => "*"
case s => "(" + s + ")"
}
@folone
folone / isomonoid.scala
Last active December 15, 2015 07:39
Monoid instance throught an isomorphism
scala> import scalaz._
import scalaz._
scala> import std.option.optionFirst
import std.option.optionFirst
scala> import syntax.monoid._
import syntax.monoid._
scala> import Isomorphism._
@folone
folone / adjunction.scala
Last active December 15, 2015 07:18
- Things, that can be described as Adjunctions - Things, that can be described as Cofree - Things, that can be described as Free monads, inspired by http://yow.eventer.com/yow-2012-1012/lambda-the-ultimate-dependency-injection-framework-by-runar-bjarnason-1277
type State[E] = Adjunction[({type λ[α] = Writer[E, α]})#λ, ({type λ[α] = Reader[E, α]})#λ]
type Store[E] = Adjunction[({type λ[α] = Reader[E, α]})#λ, ({type λ[α] = Writer[E, α]})#λ]
type Cont = Adjunction[Function0, Function0] // Function0 -| Function0
@folone
folone / 0.prelude.md
Last active December 13, 2015 22:59
@folone
folone / gist:4946543
Last active December 13, 2015 17:18
Hanoi towers at compile time become very easy with dependent types. https://gist.github.com/travisbrown/3772462
> shapeless-core/console
[warn] Credentials file /home/folone/.ivy2/.credentials does not exist
[info] Compiling 24 Scala sources to /home/folone/workspace/shapeless/core/target/scala-2.11/classes...
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.11.0-20130205-141957-132e09fc2e (OpenJDK 64-Bit Server VM, Java 1.7.0_09).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import shapeless.SingletonTypes._
@folone
folone / gist:4945168
Last active April 27, 2017 13:10
A taste of dependent types in scala with shapeless.
> shapeless-core/console
[warn] Credentials file /home/folone/.ivy2/.credentials does not exist
[info] Compiling 24 Scala sources to /home/folone/workspace/shapeless/core/target/scala-2.11/classes...
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.11.0-20130205-141957-132e09fc2e (OpenJDK 64-Bit Server VM, Java 1.7.0_09).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import shapeless._
shapeless [0849b6f...] % sbt
[info] Loading project definition from /home/folone/workspace/shapeless/project
[info] Set current project to shapeless (in build file:/home/folone/workspace/shapeless/)
> shapeless-core/console
[warn] Credentials file /home/folone/.ivy2/.credentials does not exist
[info] Compiling 2 Scala sources to /home/folone/workspace/shapeless/core/target/scala-2.11/classes...
[info] Compiling 24 Scala sources to /home/folone/workspace/shapeless/core/target/scala-2.11/classes...
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.11.0-20130205-141957-132e09fc2e (OpenJDK 64-Bit Server VM, Java 1.7.0_09).
% ghci
GHCi, version 7.6.1: http://www.haskell.org/ghc/ :? for help
Loading package ghc-prim ... linking ... done.
Loading package integer-gmp ... linking ... done.
Loading package base ... linking ... done.
Prelude> let n = map show [1..10]
Prelude> let c = \x y -> concat ["(", x, "+", y, ")"]
Prelude> foldl c "0" n
"((((((((((0+1)+2)+3)+4)+5)+6)+7)+8)+9)+10)"
Prelude> foldr c "0" n