Skip to content

Instantly share code, notes, and snippets.

View folone's full-sized avatar
🏔️

George Leontiev folone

🏔️
View GitHub Profile
@jrudolph
jrudolph / TowersOfHanoi.scala
Created February 19, 2009 13:51
Scala-Metaprogramming: Towers of Hanoi
/*
* This is the Towers of Hanoi example from the prolog tutorial [1]
* converted into Scala, using implicits to unfold the algorithm at
* compile-time.
*
* [1] http://www.csupomona.edu/~jrfisher/www/prolog_tutorial/2_3.html
*/
object TowersOfHanoi {
import scala.reflect.Manifest
@retronym
retronym / type-bounds.scala
Created December 16, 2009 11:17
Tour of Scala Type Bounds
class A
class A2 extends A
class B
trait M[X]
//
// Upper Type Bound
//
def upperTypeBound[AA <: A](x: AA): A = x
@retronym
retronym / power-mode.scala
Created July 19, 2010 18:04
Using Power Mode in the Scala REPL to find the parameter names of a method
scala> :power
** Power User mode enabled - BEEP BOOP **
** scala.tools.nsc._ has been imported **
** New vals! Try repl, global, power **
** New cmds! :help to discover them **
** New defs! Type power.<tab> to reveal **
scala> val s = repl.stringToCompilerType("scala.Some")
s: repl.compiler.Type = object Some
@codedot
codedot / lambdabetaeta
Created October 23, 2010 09:53
From ordinary variables x, y, z… to λβη
x ∈ Λ; Лямбда-выражения строятся из переменных
M, N ∈ Λ ⇒ λx.M ∈ Λ ∧ M N ∈ Λ; с помощью абстракций и аппликаций;
(M) = M, M N P = (M N) P. причем аппликация лево-ассоциативна.
x[x := P] = P; Подстановка заменяет вхождения переменной на другое выражение,
y[x := P] = y; но только если переменная совпадает,
(λx.M)[x := P] = λx.M; при этом связанные переменные не подлежат подстановке;
(λy.M)[x := P] = λy.M[x := P]; операция подстановки через абстракции
(M N)[x := P] = M[x := P] N[x := P]. и аппликации проходит выражение рекуррентно.
@defunkt
defunkt / zombies.md
Created December 29, 2010 22:57
—All You Zombies— by Robert A. Heinlein

All You Zombies

2217 Time Zone V (EST) 7 Nov. 1970--NTC-- "Pop's Place": I was polishing a brandy snifter when the Unmarried Mother came in. I noted the time---10:17 P. M. zone five, or eastern time, November 7th, 1970. Temporal agents always notice time and date; we must.

The Unmarried Mother was a man twenty--five years old, no taller than I am, childish features and a touchy temper. I didn't like his looks---I never had---but he was a lad I was here to recruit, he was my boy. I gave him my best barkeep's smile.

Maybe I'm too critical. He wasn't swish; his nickname came from what he always said when some nosy type asked him his line: "I'm an unmarried mother." If he felt less than murderous he would add: "at four cents a word. I write confession stories."

If he felt nasty, he would wait for somebody to make something of it. He had a lethal style of infighting, like a female cop---reason I wanted him. Not the only one.

@viktorklang
viktorklang / ScalaEnum.scala
Created June 30, 2011 23:12
DIY Scala Enums (with optional exhaustiveness checking)
trait Enum { //DIY enum type
import java.util.concurrent.atomic.AtomicReference //Concurrency paranoia
type EnumVal <: Value //This is a type that needs to be found in the implementing class
private val _values = new AtomicReference(Vector[EnumVal]()) //Stores our enum values
//Adds an EnumVal to our storage, uses CCAS to make sure it's thread safe, returns the ordinal
private final def addEnumVal(newVal: EnumVal): Int = { import _values.{get, compareAndSet => CAS}
val oldVec = get
@copumpkin
copumpkin / Prime.agda
Last active December 25, 2023 19:01
There are infinite primes
module Prime where
open import Coinduction
open import Data.Empty
open import Data.Nat
open import Data.Nat.Properties
open import Data.Nat.Divisibility
open import Data.Fin hiding (pred; _+_; _<_; _≤_; compare)
open import Data.Fin.Props hiding (_≟_)
@klapaucius
klapaucius / post.md
Created November 17, 2011 18:43
! vs unsafeIndex

Ответ на вопрос в этом посте.

Для начала слегка модифицируем код, чтоб он компилировался.

import qualified Data.List.Stream as S
import qualified Data.Vector.Unboxed as U

f n = let arr = U.enumFromTo 1 n 
      in S.sum $ S.map (\i -> arr U.! (i `rem` n)) $ S.unfoldr (\i -> if i < n then Just (i, i+1) else Nothing) 0
@SethRobertson
SethRobertson / index.md
Created January 14, 2012 18:29
On undoing, fixing, or removing commits in git
@arosien
arosien / gist:1712108
Created January 31, 2012 18:41
scalaz operator cheat sheet
F[A] // A is a Functor
M[A] // A is a Monad
fa: F[A], a: A // variables used below
fa1 |+| fa2 // binary append (SemiGroup)
fa1 >| fa2 // map (Functor)
fa1 >>= fa2 // flatmap (Bind)
fa1 |>| fa2 // foreach (Each)
fa <**> fb { (a, b) => c } // apply, produces F[C]