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
type var = string | |
type term = Var of var | |
| Lam of var * term | |
| App of term * term | |
| Fix of var * term (* only used for functions *) | |
| Lit of int | |
type value = Int of int | |
| Fun of (value -> value) |
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
import System.Environment (getArgs) | |
import Control.Monad (guard, forM_) | |
import System.Random (RandomGen) | |
import qualified System.Random as Random | |
import Data.Map.Strict (Map) | |
import qualified Data.Map.Strict as Map |
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
module Main where | |
import Data.List (minimumBy) | |
import Data.Ord (comparing) | |
import Data.Maybe (fromJust) | |
import Data.Map.Strict (Map) | |
import qualified Data.Map.Strict as Map | |
-- Unknown: a list of ((x,y), options) for each cell (x,y). | |
type Unknown = [((Int, Int), [Int])] |
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
import copy, random | |
n = 9 | |
values = list(range(n)) | |
def to_matrix(d): | |
return [[d[(x,y)] for y in range(n)] for x in range(n)] | |
def sudoku(): | |
known = dict() | |
unknown = {(x,y): set(values) |
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
import copy, random | |
n = 4 | |
values = list(range(n)) | |
def to_matrix(d): | |
return [[d[(x,y)] for y in range(n)] for x in range(n)] | |
def sudoku(): | |
known = dict() | |
unknown = {(x,y): set(values) |
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
-- see https://gist.github.com/rntz/c2996e06301d9ae95ee0c7a9b43f5e0d for comparison | |
module GuardedKanren where | |
import Control.Monad (liftM2, guard) | |
import Control.Applicative | |
data Stream a = Nil | Cons a (Stream a) | Later (Stream a) | |
deriving (Show) | |
instance Functor Stream where |
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 --guarded #-} | |
module GuardedKanren where | |
open import Agda.Primitive using (Level) | |
private variable | |
l : Level | |
A B : Set l | |
data Bool : Set where true false : Bool | |
if_then_else_ : ∀{A : Set} → Bool → A → A → A |
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
#lang racket | |
(require racket/hash) ;; hash-union | |
;; UNIFICATION VAR | |
;; symbol beginning with ? | |
(define (var? x) (and (symbol? x) (string-prefix? (symbol->string x) "?"))) | |
(define/contract (var x) (-> symbol? var?) | |
(string->symbol (format "?~a" x))) | |
(define/contract (var-name x) (-> var? symbol?) |
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
#lang racket | |
(struct rig (zero? sum product) #:prefab) | |
(define the-rig (make-parameter #f)) | |
(define (the-rig-zero? x) ((rig-zero? (the-rig)) x)) | |
(define (the-rig-sum args) ((rig-sum (the-rig)) args)) | |
(define (the-rig-product args) ((rig-product (the-rig)) args)) | |
(define (the-rig-+ . args) (the-rig-sum args)) | |
(define (the-rig-* . args) (the-rig-product args)) | |
(define (the-rig-zero) (the-rig-+)) |
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 FunctionalDependencies #-} | |
{-# LANGUAGE ScopedTypeVariables #-} | |
module IncrementalStreams where | |
import Prelude hiding (init) | |
import Data.Foldable (toList) | |
import qualified Data.Set as Set | |
import Data.Set (Set) | |
import qualified Data.Map as Map | |
import Data.Map (Map) |
NewerOlder