Skip to content

Instantly share code, notes, and snippets.

@AndrasKovacs
AndrasKovacs / HOASOnly.hs
Last active February 27, 2024 15:50
HOAS-only lambda calculus
{-# language BlockArguments, LambdaCase, Strict, UnicodeSyntax #-}
{-|
Minimal dependent lambda caluclus with:
- HOAS-only representation
- Lossless printing
- Bidirectional checking
- Efficient evaluation & conversion checking
Inspired by https://gist.github.com/Hirrolot/27e6b02a051df333811a23b97c375196
@Hirrolot
Hirrolot / CoC.ml
Last active May 15, 2024 14:28
How to implement dependent types in 80 lines of code
type term =
| Lam of (term -> term)
| Pi of term * (term -> term)
| Appl of term * term
| Ann of term * term
| FreeVar of int
| Star
| Box
let unfurl lvl f = f (FreeVar lvl)
@ChrisPenner
ChrisPenner / DynamicBFS.hs
Created May 12, 2022 18:38
Effectful, lazy, BFS using LogicT.
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE TypeApplications #-}
module BFS where
import Control.Applicative
import Control.Monad.Logic
import Control.Monad.Reader
@rampion
rampion / HyperList.hs
Last active April 6, 2024 19:16
Demonstration of how the Hyperfunction implementation of list works.
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE Rank2Types #-}
{-# LANGUAGE TypeOperators #-}
{-# OPTIONS_GHC -Wall -Werror -Wextra -Wno-name-shadowing #-}
module HyperList where
import Data.Function ((&))
newtype a -&> b = Hyp {invoke :: (b -&> a) -> b}
-- Based on: http://augustss.blogspot.com/2007/10/simpler-easier-in-recent-paper-simply.html
import Data.List (delete, union)
{- HLINT ignore "Eta reduce" -}
-- File mnemonics:
-- env = typing environment
-- vid = variable identifier in Bind or Var
-- br = binder variant (Lambda or Pi)
-- xyzTyp = type of xyz
-- body = body of Lambda or Pi abstraction
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE DeriveFunctor #-}
{-# LANGUAGE DeriveTraversable #-}
{-# LANGUAGE RankNTypes #-}
module Recurser where
import Control.Lens
import Data.Monoid
import Data.Foldable
import Data.Functor.Contravariant
@pwm
pwm / Contributing.md
Created June 13, 2020 15:54 — forked from MarcDiethelm/Contributing.md
How to contribute to a project on Github

This text now lives at https://github.com/MarcDiethelm/contributing/blob/master/README.md. I turned it into a Github repo so you can, you know, contribute to it by making pull requests.


Contributing

If you want to contribute to a project and make it better, your help is very welcome. Contributing is also a great way to learn more about social coding on Github, new technologies and and their ecosystems and how to make constructive, helpful bug reports, feature requests and the noblest of all contributions: a good, clean pull request.

{-# LANGUAGE MonoLocalBinds #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE TypeOperators #-}
{-# LANGUAGE DeriveAnyClass #-}
{-# LANGUAGE DuplicateRecordFields #-}
module MarkerClass where
import GHC.TypeLits -- for error messages
@cjay
cjay / folds.org
Last active February 27, 2019 20:01

List folds in Haskell from a use case oriented perspective

Since the definitions in Data.Foldable are too generic, here are list-specific ones:

-- foldl f z [x1, x2, ..., xn] == (...((z `f` x1) `f` x2) `f`...) `f` xn
foldl :: (b -> a -> b) -> b -> [a] -> b
foldl f z []     = z
foldl f z (x:xs) = let z' = z `f` x
                   in foldl f z' xs
@gelisam
gelisam / CouldBe.hs
Last active February 21, 2022 13:16
Keeping track of which errors have and haven't been handled
-- in response to https://www.parsonsmatt.org/2018/11/03/trouble_with_typed_errors.html
{-# LANGUAGE FlexibleContexts, FlexibleInstances, MultiParamTypeClasses #-}
module CouldBe where
import Control.Monad
import Data.Void
-- Here is an alternate, much simpler solution to the problem of keeping track of which errors have
-- and haven't been handled. It doesn't use prisms nor generics, it simply uses the monad