Skip to content

Instantly share code, notes, and snippets.

View folone's full-sized avatar
🏔️

George Leontiev folone

🏔️
View GitHub Profile
@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]. и аппликации проходит выражение рекуррентно.
@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
@retronym
retronym / eithert-sequence.scala
Created February 5, 2012 17:51
EitherT sequence
scala> import scalaz._, Scalaz._, effect._
import scalaz._
import Scalaz._
import effect._
scala> val listIoEither = List(EitherT[IO, Int, String](IO(Right("r"))))
listIoEither: List[scalaz.EitherT[scalaz.effect.IO,Int,String]] = List(scalaz.EitherTFunctions$$anon$20@49ab1824)
scala> val ioEitherList = listIoEither.sequenceU
ioEitherList: scalaz.EitherT[scalaz.effect.IO,Int,List[java.lang.String]] = scalaz.EitherTFunctions$$anon$20@5d38a346
@copumpkin
copumpkin / Nicomachus.agda
Last active October 3, 2015 00:38
Nicomachus's theorem
module Nicomachus where
open import Function
open import Relation.Binary.PropositionalEquality
import Relation.Binary.EqReasoning as EqReasoning
open import Data.Nat
open import Data.Nat.Properties
-- http://en.wikipedia.org/wiki/Nicomachus%27s_theorem
@larsrh
larsrh / stackoverflow.scala
Created August 30, 2012 20:31
map as function
// <http://stackoverflow.com/q/12204869>
def map[T, U, X, CC[X] <: Traversable[X]](cct: CC[T], f: T => U)(implicit cbf: CanBuildFrom[CC[T], U, CC[U]]): CC[U] =
cct.map(t => f(t))(collection.breakOut(cbf))
/*
scala> map(List(1,2,3), (x: Int) => x.toString)
res1: List[java.lang.String] = List(1, 2, 3)
*/
import java.io._
import scalaz.{ Reader => _, _ }, Scalaz._
import scalaz.effect._, IO._
import com.clarifi.machines._
object CSV extends SafeApp {
import Plan._
@tonymorris
tonymorris / Compose.scala
Created September 9, 2012 10:51
Monads (in general) do not compose
trait Functor[F[_]] {
def fmap[A, B](f: A => B, a: F[A]): F[B]
}
trait Applicative[F[_]] extends Functor[F] {
def ap[A, B](f: F[A => B], a: F[A]): F[B]
def point[A](a: A): F[A]
override final def fmap[A, B](f: A => B, a: F[A]) =
ap(point(f), a)
}
@xuwei-k
xuwei-k / basicio.hs
Created September 9, 2012 16:21
Haskell Scalaz
main = do
putStrLn "Greetings ! What is your name?"
inpStr <- getLine
putStrLn $ "Welcome to Haskell, " ++ inpStr ++ "!"
@etorreborre
etorreborre / gist:3870064
Created October 11, 2012 03:54
Unboxed union types with a context bound
/**
* this is an experiment to create unboxed union types with a phantom type and a context bound.
* All the good ideas come from @milessabin post, comments and links: http://www.chuusai.com/2011/06/09/scala-union-types-curry-howard/#comment-22
*/
/** trait for anything that can be A or B */
trait Or[A, B] {
// a phantom type, there will be no instance of this type that we'll use
type l[T]
// an alias for l[t]
@larsrh
larsrh / klist.scala
Created November 7, 2012 11:16
Compiler failure in 2.10.x
sealed trait GenericList[+M[_]] {
final def :^:[A, N[X] >: M[X]](elem: N[A]): GenericCons[N, A, this.type] =
GenericCons[N, A, this.type](elem, this)
}
case class GenericCons[M[_], H, +T <: GenericList[M]](
head: M[H],
tail: T