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
@Heimdell
Heimdell / AST.hs
Created May 25, 2014 12:56
Lambda calculus interpreter (with atoms, integers, bifs & ability to force a value calculation) to play with.
module AST where
data AST
= [Name] :=> AST
| Name :? AST
| App [AST]
| Atom String
| Const Integer
| Force AST
@Heimdell
Heimdell / records.prolog
Last active August 29, 2015 14:02
Experimental prolog records-handling library.
:- use_module(library(lists)).
construct(Fields, Record)
:- Record =.. [record | Fields]
.
% synonym
%
make --> construct.
build --> destruct.
import Control.Applicative
import Control.Monad.Reader
import Control.Monad.State
import Control.Monad.Error
import Text.Printf
data Step
@Heimdell
Heimdell / new-york-minute.hs
Last active August 29, 2015 14:04
Its all about New York Minute.
{-
This module is all about New Yourk Minutes (NYMs).
NYM is [year, month, day, hour, minute] combination where
you can uniquely determine who-is-who.
-}
import Control.Monad (guard)
import Data.List (permutations)
{- three next declarations are declaring the same thing -}
test0 :: [Int]
test0 = do
x <- [2..5] -- for all x from [2.. 5]
y <- [x - 1, x, x + 1] -- for all y from [x - 1.. x + 1]
return y -- return y
{-
module type NAME =
sig
type t
val fresh : unit -> t
end
module type STORAGE = functor (Name : NAME) ->
sig
@Heimdell
Heimdell / FreeCell.hs
Created August 17, 2014 19:43
FreeCell made readable.
{-|
Module : FreeCell
Description : A library for Freecell
Copyright : (c) Timothy Dees, 2014
License : MIT
Maintainer : [email protected]
Stability : experimental
This lets you play FreeCell. It's fun, I think.
-}
module Behaviour where
import Event
type Behaviour ref a = ref a
stepper :: EventContext clip m ref => a -> Event clip m ref a -> m (Behaviour ref a)
stepper initial event = do
behaviour <- new initial
primes = filter isPrime [1..]
isPrime p = case p of
1 -> False
2 -> True
n -> notDivisor n `all` lowerThanSqrt
where
lowerThanSqrt = takeWhile (\p -> p * p <= n) primes
:- use_module(library(clpfd)).
run(Strat) :-
empty(M),
rain_drop(M, M1),
loop(Strat, 0, M1).
loop(_, N, M) :-