Skip to content

Instantly share code, notes, and snippets.

View zelinskiy's full-sized avatar

Nikita M. Yurchenko zelinskiy

View GitHub Profile
data MailBox = MailBox {
nmessages :: Int,
size :: Int,
maxsize :: Int,
fmsg :: Message }
deriving (Eq, Show, Read)
data Message = Message {
msize :: Int,
module Category where
open import Relation.Binary.Core using (_≡_)
record Category : Set1 where
field
Objects : Set
Hom : (A B : Objects) → Set
_∘_ : ∀ {A B C} → Hom B C → Hom A B → Hom A C
∘-assoc : ∀ {A B C D} → {f : Hom A B} → {g : Hom B C} → {h : Hom C D} →
@zelinskiy
zelinskiy / AoC.agda
Last active August 26, 2017 12:32
Axiom of Choice!
data R {A B : Set} (a : A) (b : B) : Set where
--Axiom of Choice!
ac : {A B : Set} →
((a : A) → Σ B (λ b → R a b )) →
Σ (A → B) (λ f → ((a : A) → R a (f a)))
ac g = (λ a → π₁ (g a)) , (λ a → π₂ (g a))
type Checkpointed a = (a -> Cont a a) -> Cont a a
checkpointed :: (a -> Bool) -> Checkpointed a -> Cont r a
checkpointed p cp =
pure $ evalCont $ cp $ \a ->
cont $ \c ->
if p $ c a then c a else a
addTens :: Int -> Checkpointed Int
addTens x1 checkpoint = do
{-# LANGUAGE ExistentialQuantification #-}
{-# LANGUAGE TypeOperators #-}
import Data.Char
import Control.Monad
import Data.Array.IArray
import Data.Array.MArray
import Data.Array.ST
import Data.List
import Data.Maybe
import Data.List
inf = 1000000
mindist d x [] = inf
mindist d x (y:ys) | x == y = d
mindist d x (y:ys) = mindist (d+1) x ys
change _ _ [] = error "Empty List"
change x y (p : ps)
import Data.List
-- https://en.wikipedia.org/wiki/Banker%27s_algorithm
-- https://uk.wikipedia.org/wiki/%D0%90%D0%BB%D0%B3%D0%BE%D1%80%D0%B8%D1%82%D0%BC_%D0%B1%D0%B0%D0%BD%D0%BA%D1%96%D1%80%D0%B0#cite_note-3
data Resource = Resource { nameR :: String, totalR :: Int } deriving (Eq, Show)
data ProcessResourceInfo = ProcessResourceInfo { resourceP :: Resource, usedP :: Int, maxresP :: Int } deriving (Eq, Show)
type Process = [ProcessResourceInfo]
rA = Resource "A" 6
@zelinskiy
zelinskiy / T.agda
Created June 16, 2017 16:58 — forked from CodaFi/T.agda
System T, a formulation of Church's Simple Theory of Types in Agda. From ~( http://publish.uwo.ca/~jbell/types.pdf ); Church's paper at ~( https://www.classes.cs.uchicago.edu/archive/2007/spring/32001-1/papers/church-1940.pdf )
{- A straightforward version of Church’s simple type theory is the following system T -}
module T where
open import Data.Nat
-- The type of contexts.
data Γ (X : Set) : Set where
ε : Γ X
_::_ : (γ : Γ X) → X → Γ X
infixl 4 _::_
data ℕ : Set where
Z : ℕ
S : ℕ → ℕ
{-# BUILTIN NATURAL ℕ #-}
infix 4 _≅_
data _≅_ {ℓ} {A : Set ℓ} (x : A) : {B : Set ℓ} → B → Set ℓ where
refl : x ≅ x
@zelinskiy
zelinskiy / UntypedLambda.agda
Created June 22, 2017 15:06 — forked from gallais/UntypedLambda.agda
Interpreting the untyped lambda calculus in Agda
{-# OPTIONS --copatterns #-}
module UntypedLambda where
open import Size
open import Function
mutual
data Delay (A : Set) (i : Size) : Set where