Skip to content

Instantly share code, notes, and snippets.

View thelissimus's full-sized avatar

kei thelissimus

View GitHub Profile
@thelissimus
thelissimus / Assistant.hs
Created June 27, 2024 16:12
Example of telegram-bot-simple issue with sendMessageMessageEffectId
{-# LANGUAGE OverloadedStrings #-}
module Assistant (module Assistant) where
import Data.Kind (Type)
import Data.Text (Text)
import Telegram.Bot.API (Token (..), Update, defaultTelegramClientEnv)
import Telegram.Bot.Simple (BotApp (..), startBot_, (<#))
import Telegram.Bot.Simple qualified as TBS
module Lib (module Lib) where
import Control.Applicative (Applicative (liftA2))
import Data.Foldable
import Data.Functor ((<&>))
-- OCaml be like:
-- +
incrementInt :: Int -> Int
incrementInt n = n + 1
@thelissimus
thelissimus / LawfulEquality.lean
Created June 6, 2024 15:03
Explanation of Lawful Equality.
import Batteries.Data.RBMap.Basic
open Batteries
-- `Ordering` is used instead of mainstream languages' approach with (-1, 0, 1) and consits of:
-- lt - less than (-1)
-- eq - equals (0)
-- gt - greater than (1)
-- This one sparks joy.
@thelissimus
thelissimus / STLCBool.lean
Created May 25, 2024 12:50
STLC-like interpreted language in Lean 4
import Batteries.Data.RBMap
inductive BinOp where
| add | sub | mul | div
deriving Repr, Ord
-- Abstrct Syntax Tree
inductive Expr where
| bool (value : Bool)
| num (value : Int)
@thelissimus
thelissimus / STLC.lean
Created May 25, 2024 12:18
STLC-like interpreted language in Lean 4
import Batteries.Data.RBMap
inductive BinOp where
| add | sub | mul | div
deriving Repr, Ord
-- Abstrct Syntax Tree
inductive Expr where
| num (value : Int)
| var (name : String)
@thelissimus
thelissimus / DI.hs
Created May 12, 2024 09:25
Dependency Injection in Haskell.
{-# LANGUAGE ImplicitParams #-}
module DI (module DI) where
import Control.Monad.Reader (MonadReader (ask), ReaderT (runReaderT))
data Database = MkDatabase
data User = MkUser deriving (Show)
data Request = MkRequest Int
data Response = MkResponse String
@thelissimus
thelissimus / 1_sort.ts
Last active April 21, 2024 08:57
Explanation of type classes using TypeScript and Scala. (WIP)
/// Usecases.
type Ordering =
| -1 // Less than
| 0 // Equal
| 1; // Greater than
const LT: Ordering = -1;
const EQ: Ordering = 0;
const GT: Ordering = 1;
@thelissimus
thelissimus / main.go
Last active April 16, 2024 11:51
Better resource management in Go using "Bracket pattern".
package main
import (
"io/fs"
"os"
)
// Manual
func bracket[R any](acquire func() (R, error), release func(R) error, use func(R) error) error {
r, err := acquire()
@thelissimus
thelissimus / lint.pl
Created April 15, 2024 12:38
LInt implemented in Prolog.
exp(E) --> int(E).
exp(E) --> binop(E).
int(I) --> [I], { integer(I) }.
binop(add(A, B)) --> "+", exp(A), exp(B).
binop(sub(A, B)) --> "-", exp(A), exp(B).
binop(mul(A, B)) --> "*", exp(A), exp(B).
binop(div(A, B)) --> "/", exp(A), exp(B).
@thelissimus
thelissimus / Ethers.res
Created April 8, 2024 18:27
ReScript FFI example bindings for ethers.
@module("ethers") external decodeBase58Unsafe: string => bigint = "decodeBase58"
@get external code: Js.Exn.t => string = "code"
@get external argument: Js.Exn.t => string = "argument"
@get external value: Js.Exn.t => string = "value"
@get external shortMessage: Js.Exn.t => string = "shortMessage"
type decodeBase58Error =
| UnknownError
| InputError({