Skip to content

Instantly share code, notes, and snippets.

View andreasabel's full-sized avatar

Andreas Abel andreasabel

View GitHub Profile
@andreasabel
andreasabel / Exp.cf
Created April 10, 2022 20:19
Interpreter for C-style expression in Linear Haskell
-- BNFC grammar for C-style arithmetic expressions
-- Build parser with: bnfc --haskell --generic -d -m Exp.cf && make
EVar. Exp2 ::= Ident;
EInt. Exp2 ::= Integer;
EPlus. Exp1 ::= Exp1 "+" Exp2;
EAss. Exp ::= Ident "=" Exp1;
coercions Exp 2;
@andreasabel
andreasabel / LeftistHeap.agda
Created January 13, 2022 12:28
Leftist heaps as indexed data types in Agda
{-# OPTIONS --postfix-projections #-}
{-# OPTIONS --termination-depth=2 #-}
-- Leftist heaps (Knuth 1973).
-- An implementation of priority queues.
-- Tested with Agda v2.6.2 and agda-stdlib v1.7.
-- The module is parametrized over the type of the elements
-- stored in the heap. These elements need to be totally ordered,
@andreasabel
andreasabel / Mondrian.hs
Created December 20, 2021 09:28
A backtracking solver for the Mondrian puzzle in Haskell (purely declaratively, list-based, no arrays)
-- | The Mondrian puzzle.
-- <https://www.wissenschaft-shop.de/spiele-mit-iq/Mondrian-Blocks-wiss.html>
--
-- Task: place on a 8x8 board (64 squares) tiles of sizes
--
-- * 1x1, 1x2, 1x3, 1x4, 1x5 (15 squares occupied)
-- * 2x2, 2x3, 2x4, 2x5 (28 squares)
-- * 3x3, 3x4 (21 squares)
--
-- Strategy:
@andreasabel
andreasabel / Additions-to-Haskell-Prelude.md
Last active December 8, 2021 21:02
Additions to Haskell's `Prelude` since `base-4.0.0.0`

Additions to Haskell's Prelude since base-4.0.0.0

base version additions
4.8.0.0 *> <$ <$> <* <*> Applicative Foldable Monoid Traversable Word foldMap mappend mconcat mempty pure sequenceA traverse
4.9.0.0 errorWithoutStackTrace
4.11.0.0 <> Semigroup
4.13.0.0 MonadFail
@andreasabel
andreasabel / Makefile
Created December 8, 2021 17:13
Extracting "since" information for GHC Warnings from the published documentation
# Andreas Abel, 2021-07-15
# A Makefile to extract 'since' information for GHC warnings from published documentation in html.
# Variables
# GHC versions
oldVersions = 5.04.3 6.0.1 6.2.2 6.4.2 6.6.1 6.8.3 6.10.4 6.12.3 7.0.4 7.4.2 7.6.3 7.8.4 7.10.3
newVersions = 8.0.2 8.2.2 8.4.4 8.6.5 8.8.4 8.10.5 9.0.1
allVersions = $(oldVersions) $(newVersions)