Skip to content

Instantly share code, notes, and snippets.

View chshersh's full-sized avatar
🕵️‍♂️
Working on a super-secret OCaml project

Dmitrii Kovanikov chshersh

🕵️‍♂️
Working on a super-secret OCaml project
View GitHub Profile
@chshersh
chshersh / lam.ml
Last active February 5, 2024 14:15
An OCaml pretty-printer and parser for Untyped Lambda Calculus
(* Type *)
type expr =
| Var of string
| App of expr * expr
| Lam of string * expr
(* Pretty printer *)
let rec pretty = function
@chshersh
chshersh / install.sh
Last active January 3, 2024 12:50
Installing from GitHub releases
#!/bin/bash
set -Eeuxo pipefail
# This script installs a developer tool on your machine
# by downloading an executable (ideally, statically linked)
# from GitHub releases
## Example: ripgrep
dir=$(mktemp --tmpdir --directory ripgrep-XXXX)
@chshersh
chshersh / CPS.hs
Last active July 5, 2022 10:18
CPS transformed code
-- Code for the following blog post:
-- https://kodimensional.dev/cps
{-# LANGUAGE LambdaCase #-}
module CPS where
data AppError
= UserSessionIsInvalid
| DbError InternalDbError
@chshersh
chshersh / welcome-to-the-haskell-land-chords.txt
Last active May 3, 2022 06:58
Chords to the "Welcome to the Haskell-land (a Bo Burnham parody)" song
Performance:
* https://youtu.be/Uy08hw1ZyCM
Chords are taken from the original song:
* https://tabs.ultimate-guitar.com/tab/bo-burnham/welcome-to-the-internet-chords-3732602
Strumming:
* First half: Up - Muted (^ - x - ^ - x - ^ - x)
* Second half: Up - Down - Down (^ - V - V - ^ - V - V - ^ - V - V)
@chshersh
chshersh / TypeError.hs
Last active July 15, 2019 06:53
Examples of custom type errors
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleContexts #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE PolyKinds #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE TypeFamilies #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
@chshersh
chshersh / Comonad.hs
Created March 25, 2019 11:07
Comonadic builders
#!/usr/bin/env cabal
{- cabal:
build-depends:
, base ^>= 4.12.0.0
, comonad ^>= 5.0
, pretty-simple ^>= 2.2
, text
-}
{-# LANGUAGE OverloadedStrings #-}
@chshersh
chshersh / parser-combinators-vs-parser-generators.md
Last active June 12, 2023 11:06
Per criterion comparison of Parser Generators and Parser Combinators

Legend:

  • ➖ poor (impossible or very hard to achieve)
  • ➕ good (possible but requires some dancing)
  • ✔️ excellent (very easy to achieve/have)

PC stands for parser combinators and PGparser generators.

Property Generators Combinators Description
Power ✔️ LALR ➕ LL(∞) PC can't handle left-recursive grammars (though, there's some article¹...).
@chshersh
chshersh / ghci.conf
Last active December 5, 2023 00:19
Config for GHCi with pretty output
-- To run:
-- cabal repl -b pretty-simple
--
-- Colorizing and pretty-printing ghci output
-- requires: pretty-simple
:set -interactive-print=Text.Pretty.Simple.pPrint
-- green bold lambdas and multiline mode
:set prompt "\ESC[1;32mλ: \ESC[m"
:set prompt-cont "\ESC[1;32mλ| \ESC[m"
@chshersh
chshersh / ArrayFun.hs
Last active August 15, 2019 05:27
Emulating array syntax with lens
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TemplateHaskell #-}
{-# LANGUAGE ViewPatterns #-}
-- | This module contains some approach for emulating array syntax from
-- imperative languages. The approach emulates only syntax, not efficiency.
-- Though if you like working with persistent arrays it may be good for you.
-- Also it's a fun exercise on lenses.