Skip to content

Instantly share code, notes, and snippets.

View folone's full-sized avatar
🏔️

George Leontiev folone

🏔️
View GitHub Profile
trait λ { type ap[_<:λ]<:λ }
type I = λ{type ap[X<:λ] = X }
type K = λ{type ap[X<:λ] = λ{type ap[Y<:λ] = X }}
type S = λ{type ap[X<:λ] = λ{type ap[Y<:λ] = λ{type ap[Z<:λ] = X#ap[Z]#ap[Y#ap[Z]] }}}
type Y = S#ap[I]#ap[I]#ap[S#ap[I]#ap[I]]
!! fonts
Xft.dpi: 86
Xft.antialias: true
Xft.autohint: false
Xft.hinting: true
! hintnone, hintslight, hintmedium, hintfull
Xft.hintstyle: hintmedium
Xft.rgba: rgb
! lcdnone, lcddefault, lcdlight, lcdlegacy
Xft.lcdfilter: lcddefault
@folone
folone / lens.scala
Created November 29, 2011 10:28
Scalaz partial modification of immutable objects
scala> import scalaz._
import scalaz._
scala> case class Person(name: String, age: Int)
defined class Person
scala> val nameLens: Lens[Person, String] =
| Lens((p: Person) => p.name,
| (p: Person, changed: String) => p.copy(name = changed))
nameLens: scalaz.Lens[Person,String] = Lens(<function1>,<function2>)
@folone
folone / gist:1447544
Created December 8, 2011 16:42
roy-mode
(require 'generic-x)
(defvar roy-keywords
'("with" "macro" "return" "bind" "do" "case" "match"
"type" "data" "else" "then" "if" "fn" "let" "true" "false")
"Roy keywords.")
;;
;; Syntax highligh
;;
-- 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
@folone
folone / skiapplicative.hs
Created March 6, 2012 15:29
Illustration to The Monad Reader issue 17, The Reader Monad and Abstraction Elimination by Petr Pudlak
import Control.Applicative
main = print $ answer succ 0 where
one = pure <*> (pure :: a -> b -> a)
inc = (<*>) ((<*>) <$> pure)
mul = (<*>) <$> pure
h = mul <*> inc
answer = h . h . h $ one
@folone
folone / nodeseq.scala
Created July 31, 2012 14:04
NodeSeq instance for scalacheck
> console
[info] Starting scala interpreter...
[info]
Welcome to Scala version 2.9.2 (OpenJDK 64-Bit Server VM, Java 1.6.0_24).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scala.xml._
import scala.xml._
\documentclass{tufte-handout}
%\geometry{showframe}% for debugging purposes -- displays the margins
\usepackage{amsmath}
% Set up the images/graphics package
\usepackage{graphicx}
\setkeys{Gin}{width=\linewidth,totalheight=\textheight,keepaspectratio}
\graphicspath{{graphics/}}
@folone
folone / haskell.hs
Last active October 10, 2015 11:58
Pointers
class Monad m => Ref r m where
ref :: a -> m (r a)
(*) :: r a -> m a
(*=) :: r a -> a -> m ()
(*$) :: r a -> (a -> a) -> m ()
r *$ f = (r *) >>= (*=) r . f
instance Ref IORef IO where
ref = newIORef
(*) = readIORef
@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)] =