Skip to content

Instantly share code, notes, and snippets.

View lizzabees's full-sized avatar

Elizabeth Ryan lizzabees

  • EA
  • Seattle, WA
View GitHub Profile
@lizzabees
lizzabees / parsin1.output.md
Created October 23, 2023 04:40
parsing in unison part1

Parsing in Unison Part 1: Combinator Combo

Come with me as I explore different approaches to parsing in Unison! I'm prone to getting a little too wordy and going on tangents, so I will do my best to keep this focused and concrete. If you're reading this, the odds are high that you're familiar with most of what I'll be covering. This is written as a Unison transcript, which is really neat! There will also be Haskell code and possibly some C at some point. I will assume you have some experience with all of that, as well as some knowledge and practice when it comes to parsing. One last thing before we get to work -- I am a professional novice and you should not take what I say as authoritative. If I say something incorrect or make mistakes (especially likely when I talk about any of the formal basis for this stuff), please reach out!

Parsec

Alright! Lets start with parser combinators! They're (deceptively) simple, powerful, well known, and ideal for a functional setting. I'm

@lizzabees
lizzabees / unisyn.u
Last active September 24, 2023 03:09
parser combinators and regex in unison
unique type ErrorItem is i
= EOI
| Any
| One i
| Many is
| Named Text
| Not (ErrorItem is i)
unique type ParseError e is i
= Expected [(ErrorItem is i)] [(ErrorItem is i)]
@lizzabees
lizzabees / wordle.hs
Last active January 20, 2022 23:37
wordle solver
#!/usr/bin/env cabal
{- cabal:
build-depends: base ^>=4.14.3.0
, parsec
-}
module Main where
import Control.Monad (forever, unless)
import Data.Functor ((<&>))
import Data.List (intersperse)
@lizzabees
lizzabees / freq.c
Created January 15, 2022 22:28
wordle char frequencies (c)
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
typedef struct entry {
char letter;
int count;
} entry;
@lizzabees
lizzabees / freq.rs
Last active January 15, 2022 22:37
wordle char frequencies (rust)
#!/usr/bin/env cargo-script script
use std::collections::HashMap;
use std::fs::File;
use std::io::prelude::*;
use std::io::{BufReader, Result};
use std::iter;
fn main() -> Result<()> {
let fp = File::open("/usr/share/dict/words")?;
let mut reader = BufReader::new(fp);
@lizzabees
lizzabees / Main.hs
Last active January 15, 2022 20:23
wordle character frequencies
#!/usr/bin/env cabal
{- cabal:
build-depends: base ^>=4.14.3.0
, containers
-}
module Main where
import Control.Monad.ST
import Data.List (sortOn)