module natcomp where
open import Data.Nat using (ℕ; _+_)
open import Data.List using (List; []; _∷_; _++_)
open import Data.List.Properties using (++-assoc)
open import Data.Maybe using (Maybe; just; nothing; _>>=_)
open import Relation.Binary.PropositionalEquality using (_≡_; refl; cong)
open Relation.Binary.PropositionalEquality.≡-Reasoning
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# OPTIONS_GHC -Wno-unrecognised-pragmas #-} | |
{-# HLINT ignore "Use list comprehension" #-} | |
import Data.IORef ( IORef, newIORef, readIORef, writeIORef ) | |
import GHC.IO ( unsafePerformIO ) | |
import Control.Applicative ( Alternative(..) ) | |
import Control.Monad ( when ) | |
import Debug.Trace | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(* language definition *) | |
type nom = string | |
type bop = Add | Sub | Mul | |
type typ = | |
| Int | Arrow of typ * typ | Meta of meta | |
and meta = meta_state ref | |
and meta_state = | |
| Solved of typ | |
| Unsolved of nom (* keep name for pretty printing *) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# LANGUAGE StrictData, DerivingVia, OverloadedRecordDot #-} | |
{- | |
(compiled with GHC 9.4.2) | |
-} | |
{- | |
HEADS UP | |
this is an example implementation of a non-trivial type system using bidirectional type checking. | |
it is... |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
%{ | |
(** the [Surface] module contains our AST. *) | |
open Surface | |
(** exception raised when a [nonempty_list] returns an empty list. *) | |
exception EmptyUnfolding | |
(** desugars `(x y z : a) -> b` into `(x : a) -> (y : a) -> (z : a) -> b`. *) | |
let rec unfoldPi (xs : string list) (dom : expr) (cod : expr) : expr = | |
match xs with |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# OPTIONS --without-K #-} | |
import Relation.Binary.PropositionalEquality as Eq | |
open Eq using (_≡_; refl) | |
pattern erefl x = refl {x = x} | |
--- path induction --- | |
J : ∀ {A : Set} → |