Skip to content

Instantly share code, notes, and snippets.

{-# LANGUAGE OverloadedStrings #-}
module Main where
import Control.Applicative ((<|>))
import qualified Data.SCargot as SCargot
import qualified Data.SCargot.Language.Basic as SCargot
import Data.SCargot.Repr.Basic
import Data.Text (Text)
import qualified Text.Parsec as Parsec
@aisamanra
aisamanra / callbacks.rs
Last active February 5, 2023 18:21
Creating a HashMap of closures in Rust
#![feature(unboxed_closures)]
#![feature(core)]
#![feature(io)]
use std::old_io::stdio::{stdin};
use std::collections::HashMap;
// This is our toy state example.
#[derive(Debug)]
struct State {
@aisamanra
aisamanra / tokile.rb
Created March 10, 2022 03:56
A terminal-based Wordle clone for four-letter Toki Pona words
require 'csv'
require 'set'
module Tokile
YELLOW = "\x1b[33m"
GREEN = "\x1b[32m"
CLEAR = "\x1b[39m"
UP = "\033[F"
@aisamanra
aisamanra / pratt.hs
Created March 11, 2016 22:22
a simple pratt parser in Haskell
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
import Data.Map.Strict (Map)
import qualified Data.Map.Strict as M
import MonadLib
type Tables t a = (PrefixMap t a, InfixMap t a)
newtype PrattM t r a = PrattM
{ runPrattM :: ReaderT (Tables t r) (StateT [t] (ExceptionT String Id)) a
@aisamanra
aisamanra / Makefile
Created May 17, 2019 00:28
C++ module example
CPPFLAGS = -std=c++1z -fmodules-ts
ALL: main
main: speech.o main.cc
clang++ $(CPPFLAGS) -fprebuilt-module-path=. -o $@ $^
speech.o: speech.pcm
clang++ $(CPPFLAGS) -o $@ -c $<
#[derive(Debug)]
enum Expr {
Var { x: u32 },
App { f: ExprRef, arg: ExprRef },
Lam { body: ExprRef },
}
use Expr::*;
#[derive(Debug, Copy, Clone)]
@aisamanra
aisamanra / jsonfs.hs
Created November 13, 2014 07:17
Quick-and-dirty program to mount JSON as a read-only file system
{-# LANGUAGE OverloadedStrings #-}
-- WARNING! This is very bad, quickly-written code, and should not be
-- trusted to do anything right! It does not support writing, and still
-- has several problems even for reading. Also it's ugly and bad.
import qualified Data.ByteString as BSS
import Data.ByteString.Lazy (ByteString)
import qualified Data.ByteString.Lazy as BS
import Data.Char (isDigit)
@aisamanra
aisamanra / untyped.rs
Last active April 10, 2018 23:45
Basic Rust implementation of an interpreter for the untyped lambda calculus
// A basic intepreter for the untyped lambda calculus
enum Term
{ Num(int)
, Var(~str)
, Lam(~str, ~Term)
, App(~Term, ~Term)
, Let(~str, ~Term, ~Term)
}
/* This is a naive implementation of Jonathan McCabe's elaboration of
* Alan Turing's model of morphogenesis, as described here:
* http://www.jonathanmccabe.com/Cyclic_Symmetric_Multi-Scale_Turing_Patterns.pdf
*/
extern crate rand;
use rand::Rng;
use std::env;
use std::io::Write;
main: libsample.a
gcc -lpthread -ldl main.c libsample.a -o main
libsample.a: sample.rs
rustc --crate-type=staticlib sample.rs
clean:
rm -f main libsample.a