Skip to content

Instantly share code, notes, and snippets.

View Heimdell's full-sized avatar
🔨
Right tool for the right job

Андреев Кирилл Heimdell

🔨
Right tool for the right job
  • Ульяновск
View GitHub Profile
{-# LANGUAGE
TemplateHaskell,
Rank2Types,
NoMonomorphismRestriction,
TypeOperators,
StandaloneDeriving,
DeriveFunctor #-}
import Control.Applicative
@Heimdell
Heimdell / parser.py
Last active September 18, 2015 12:28
def split(list):
"[a] -> (a, [a])"
return [list[0], list[1:]]
def reduce(list, zero, add):
"([a], b, (b, a) -> b) -> b"
for i in range(0, len(list)):
zero = add(zero, list[i])
-- Wrapper for recursive types
data Fix f = In { out :: f (Fix f) }
-- 1-layer fold and unfold
type Algebra f a = f a -> a
type Coalgebra f a = a -> f a
cata :: Functor f => Algebra f b -> Fix f -> b
ana :: Functor f => Coalgebra f a -> a -> Fix f
#lang racket
(define (partition good? list return)
(match list
[(list)
(return `() `())]
[(list head tail ...)
(partition good? tail (λ (accepted rejected)
@Heimdell
Heimdell / nua.hs
Last active October 9, 2015 18:53
{-# LANGUAGE RankNTypes #-}
import Data.Traversable (for)
import Data.Functor.Identity
import Data.Functor.Constant
type Lens s t a b = forall f . Applicative f => (a -> f b) -> (s -> f t)
@Heimdell
Heimdell / partial.rkt
Last active October 11, 2015 11:54
Parser, which consumes input partially.
#lang racket
; await (s -> (s, parser))
; yield (result, parser)
; stop (error)
(define (await state-transform) `(await ,state-transform))
(define (yield result next) `(yield ,result ,next))
(define (stop error) `(stop ,error))
let getline return =
getchar -> c:
if equal c "\n" ?
return ""
else
getline -> s:
return (+ c s);
let putline string next =
@Heimdell
Heimdell / AST.hs
Last active October 14, 2015 10:20
{-# LANGUAGE DeriveFunctor #-}
module AST where
data AST var
= Constant String
| Variable var String
| (:->) [var] (AST var)
| Call (AST var) [AST var]
@Heimdell
Heimdell / fun.js
Last active November 7, 2015 19:21
not_implemented = function () {
throw "Implement me!"
}
map_list = not_implemented
map_nullable = not_implemented
map_function = not_implemented
assert_equal = function (x, y) {
require 'gtk3'
class App
def self.create &block
@@framestack = [Gtk::Window.new]
@@registration_on = true
flow { self.instance_eval &block }