Skip to content

Instantly share code, notes, and snippets.

View folone's full-sized avatar
🏔️

George Leontiev folone

🏔️
View GitHub Profile
scala> trait Assoc[K] { type V ; val value: V }
defined trait Assoc
scala> def mkAssoc[K, V0](k: K, v: V0): Assoc[k.type] { type V = V0 } =
| new Assoc[k.type] { type V = V0 ; val value = v }
mkAssoc: [K, V0](k: K, v: V0)Assoc[k.type]{type V = V0}
scala> def lookup[K](k: K)(implicit assoc: Assoc[k.type]): assoc.V = assoc.value
lookup: [K](k: K)(implicit assoc: Assoc[k.type])assoc.V
@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 / TReader.scala
Created October 15, 2012 10:57 — forked from tonymorris/TReader.scala
Reader monad in Scala
case class T() // your data type that you want to "implicitly" thread through
case class TReader[+A](run: T ⇒ A) {
def map[B](f: A ⇒ B): TReader[B] =
TReader((r: T) ⇒ f(run(r)))
def flatMap[B](f: A ⇒ TReader[B]): TReader[B] =
TReader((r: T) ⇒ f(run(r)).run(r))
def &&&[B](x: TReader[B]): TReader[(A, B)] =
@folone
folone / hello-ski.hs
Created August 27, 2012 08:16 — forked from shangaslammi/hello-ski.hs
Hello World using Applicative instance for ((->) r) as a computational basis
$ ghci
GHCi, version 7.4.2: 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> :l hello-ski.hs
[1 of 1] Compiling Main ( hello-ski.hs, interpreted )
Ok, modules loaded: Main.
*Main> main
Hello world!
-- courtesy of hpc on #haskell
import Unsafe.Coerce
import Control.Monad.ST
toInteger :: Int -> Integer
isJust :: Maybe a -> Bool
null :: [a] -> Bool
id :: a -> a
toInteger = unsafeCoerce