Skip to content

Instantly share code, notes, and snippets.

View eignnx's full-sized avatar

eignnx eignnx

View GitHub Profile
@eignnx
eignnx / plus-plus-arrow.pl
Last active April 11, 2021 01:15
A Prolog `term_expansion` rule for a modified DCG arrow. It automatically builds syntax trees as it parses.
:- module(cfg_macro, [
op(1200, xfx, ++>)
]).
:- op(1200, xfx, ++>).
/*
The rule:
s ++> np(blah), vp.
translates to:
@eignnx
eignnx / semantic_nom_whitespace.rs
Last active June 22, 2021 22:42
An idea for how to handle whitespace in Rust's `nom` parser-combinator library.
/// A module for parsing whitespace. Takes into account comments too.
///
/// # Module Outline
/// - mod space
/// - fn comment
/// - mod allowed
/// - fn here
/// - fn after
/// - fn before
/// - fn around
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE PatternSynonyms #-}
import Debug.Trace ( trace )
type Ident = String
data Value
= Var Ident
| Bool Bool
{-# LANGUAGE LambdaCase #-}
{-# LANGUAGE BlockArguments #-}
{-# LANGUAGE PatternSynonyms #-}
import Data.Maybe
import Control.Monad.State
import Data.List
data Ty
= Unit -- The unit type.
:- op(350, yfx, @).
:- set_prolog_flag(occurs_check, error).
:- det(inference/3).
inference(true, bool, _).
inference(false, bool, _).
@eignnx
eignnx / hindley-milner.pl
Last active January 3, 2024 16:03
An implementation of the Hindley-Milner type inference algorithm in SWI-Prolog.
:- op(600, yfx, '@'). % Function application
:- op(450, xfy, '=>'). % Type variable quantification
:- op(1150, fx, mode).
% Defines/validates a typing context.
tcx([]).
tcx([X-Sigma | Tcx]) :-
atom(X),
sigma_type(Sigma),
tcx(Tcx).