Skip to content

Instantly share code, notes, and snippets.

View nerodono's full-sized avatar
😒
У меня не отображается статус

Aleksandr nerodono

😒
У меня не отображается статус
View GitHub Profile
@nerodono
nerodono / typeck.py
Created May 18, 2024 12:42
Simplest typeck
import typing as t
from dataclasses import dataclass
Tp: t.TypeAlias = """
(
Struct
| Unknown
| Int
| Str
)
@nerodono
nerodono / Comb.py
Last active April 24, 2024 16:34
Another thing that I did on my phone (omg this was fucking suffering)
from functools import reduce as foldl
import string
import pprint
import builtins
class ParseFail(Exception):
...
def group_fails(message, *fails):
return ParseFail(f"{message}: {fails!r}")
@nerodono
nerodono / toython_tokenizer.py
Last active April 20, 2024 19:09
I wrote that on my phone because I was bored
from dataclasses import dataclass
from typing import (
Self,
Callable,
Sequence,
TypeAlias,
TypeVar,
Protocol,
Any,
)
"""Sole purpose of this thing - fix circular imports.
Consider, for example, message:
`slonogram.schemas.message.Message` depends on `slonogram.schemas.chat.Chat`
`Chat` also depends on `Message`, so that we got logically unsolvable circular imports problem.
This is the solution to it.
"""
from typing import Any, Iterable
from importlib import import_module
@nerodono
nerodono / mapper.py
Created February 8, 2024 22:00
Stupidly simple mapper
from typing import (
Generic,
TypeVar,
Protocol,
Any,
Type,
NewType,
)
T = TypeVar("T")
@nerodono
nerodono / lambda.rs
Created February 8, 2024 12:26
Lambda calculus on Rust types
trait Lam<X> {
type Result;
}
struct True0;
struct True1<X>(X);
struct False0;
struct False1<X>(X);
@nerodono
nerodono / nat-typefuck.rs
Created February 4, 2024 17:11
Silly natural numbers on types
trait Nat {
type Succ;
const NUMERIC: u64;
}
struct S<T>(T);
struct Z;
impl Nat for Z {
@nerodono
nerodono / JsonParser.hs
Last active April 23, 2024 22:53
JSON parser written in haskell: no adequate error checking, just JSON
module JsonParser where
import qualified Data.Map as M
import qualified Data.Bifunctor as Bi
import Data.Char ( ord
, chr
, isHexDigit
, isDigit
)
@nerodono
nerodono / Number.hs
Created January 12, 2024 18:55
Natural & Integer numbers definition
module Number where
data Nat = S Nat | Z
deriving(Eq)
natIntoHaskellInt :: Nat -> Int
natIntoHaskellInt Z = 0
natIntoHaskellInt (S v) = natIntoHaskellInt v + 1
instance Show Nat where
@nerodono
nerodono / LambdellCalculus.hs
Last active January 7, 2024 00:31
Lambda calculus reduction in Haskell
module LambdellCalculus where
import qualified Data.Bifunctor as Bi
data Term = ApplyT Term Term
| VarT Char
| FunT Char Term
deriving(Show, Eq)
isValidVar :: Char -> Bool