Skip to content

Instantly share code, notes, and snippets.

View pedrominicz's full-sized avatar

Pedro Minicz pedrominicz

View GitHub Profile
@pedrominicz
pedrominicz / Combinator.hs
Last active December 9, 2025 03:18
Lambda calculus to SKI combinators calculus compiler
module Combinator where
-- https://crypto.stanford.edu/~blynn/lambda/sk.html
-- http://okmij.org/ftp/tagless-final/ski.pdf
-- https://www.cantab.net/users/antoni.diller/brackets/intro.html
import Data.List
type Name = String
@pedrominicz
pedrominicz / Lambda.hs
Created March 20, 2021 19:42
Simple CEK-style lambda calculus interpreter.
module Lambda where
-- https://www.youtube.com/watch?v=O0TgP7GKkSY
-- https://gist.github.com/pedrominicz/127ab01cec689cc3d69f32e6c4f758bb
data Term
= App Term Term
| Lam Term
| Var Int
deriving (Eq, Show)
@pedrominicz
pedrominicz / Tactic.hs
Last active July 17, 2022 22:23
Unpolished tactics for extrinsic (Curry-style) lambda calculus
module Tactic where
import Data.List
-- https://totbwf.github.io/posts/tactic-haskell.html
data Type
= Var Int
| Arrow Type Type
| Prod Type Type
@pedrominicz
pedrominicz / Early.hs
Created March 12, 2021 15:49
MonadUnliftIO
{-# LANGUAGE InstanceSigs #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
module Early where
-- https://chrisdone.com/posts/exceptt-vs-early-do/
-- https://hackage.haskell.org/package/unliftio-core-0.2.0.1/docs/src/Control.Monad.IO.Unlift.html#MonadUnliftIO
-- https://hackage.haskell.org/package/unliftio-0.2.14/docs/src/UnliftIO.Internals.Async.html#concurrently
@pedrominicz
pedrominicz / Optic.hs
Created March 9, 2021 16:58
CPS based lenses
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE TupleSections #-}
module Optic where
-- https://twanvl.nl/blog/haskell/cps-functional-references
-- https://mail.haskell.org/pipermail/haskell-cafe/2007-November/035263.html
import Control.Applicative
import qualified Control.Category as Cat
@pedrominicz
pedrominicz / FRef.hs
Created March 9, 2021 16:40
Functional references (also knows as lenses)
module Optic where
import Prelude hiding (fst, (.))
import qualified Prelude
-- https://twanvl.nl/blog/haskell/overloading-functional-references
data FRef s a = FRef
{ get :: s -> a
, set :: a -> s -> s
@pedrominicz
pedrominicz / Main.hs
Last active March 9, 2021 00:09
`fused-effects` example
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GADTs #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE KindSignatures #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE UndecidableInstances #-}
module Main where
@pedrominicz
pedrominicz / Lazy.x
Last active July 19, 2022 13:31
Alex: strict and lazy bytestrings
{
module Lazy where
import Data.Foldable
import qualified Data.ByteString.Lazy as B
}
%wrapper "basic-bytestring"
$alpha = [a-zA-Z]
@pedrominicz
pedrominicz / yoneda.lean
Last active December 13, 2021 23:17
Haskell style (i.e. using `Type` as a category) proof of the Yoneda lemma
import tactic
-- https://www.youtube.com/watch?v=l1FCXUi6Vlw
namespace yoneda
class functor (f : Type → Type) : Type 1 :=
(map : ∀ {α β : Type}, (α → β) → f α → f β)
(id_map : ∀ {α : Type}, map (id : α → α) = id)
(comp_map : ∀ {α β γ : Type} (g : α → β) (h : β → γ), map h ∘ map g = map (h ∘ g))
@pedrominicz
pedrominicz / detag.py
Last active October 23, 2021 15:11
Remove a specific tag from an HTML file.
#!/usr/bin/env python3
import bs4
import sys
if len(sys.argv) != 3:
print(f'usage: {sys.argv[0]} <tag> <file>')
sys.exit(1)
with open(sys.argv[2], 'r+') as f: