Skip to content

Commit cce5a33

Browse files
committed
First commit
0 parents  commit cce5a33

34 files changed

+3147
-0
lines changed

.github/workflows/ci.yml

+22
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
name: CI
2+
3+
on:
4+
push:
5+
branches: [ main ]
6+
pull_request:
7+
branches: [ main ]
8+
9+
env:
10+
CARGO_TERM_COLOR: always
11+
12+
jobs:
13+
build:
14+
15+
runs-on: ubuntu-latest
16+
17+
steps:
18+
- uses: actions/checkout@v2
19+
- name: Build
20+
run: cargo build --verbose
21+
- name: Run tests
22+
run: cargo test --verbose

.gitignore

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
/target

Cargo.lock

+233
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

+13
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[package]
2+
name = "type-layout"
3+
version = "0.1.0"
4+
edition = "2021"
5+
6+
# See more keys and their definitions at https://doc.rust-lang.org/cargo/reference/manifest.html
7+
8+
# TODO: enable overflow checks in release builds?
9+
10+
[dependencies]
11+
12+
[dev-dependencies]
13+
insta = "1.0"

LICENSE

+21
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2021 Noah Lev
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

README.md

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# type-layout
2+
3+
**Note:** I am not currently accepting pull requests.

example.fun

+24
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
-- The type equivalent to Maybe Bool
2+
-- <None of {} | Some of <False of {} | True of {}>>
3+
4+
-- The None value (aka, Nothing)
5+
<None = {}> as <None of {} | Some of <False of {} | True of {}>>
6+
7+
-- The Some False value (aka, Just False)
8+
<Some = <False = {}> as <False of {} | True of {}>> as <None of {} | Some of <False of {} | True of {}>>
9+
10+
-- The Some True value
11+
<Some = <True = {}> as <False of {} | True of {}>> as <None of {} | Some of <False of {} | True of {}>>
12+
13+
14+
-- A basic pattern match. Equivalent to `opt.unwrap_or(false)` in Rust.
15+
alias Bool = <False of {} | True of {}> in
16+
-- Maybe Bool
17+
alias MBool = <None of {} | Some of Bool> in
18+
let Some_of_True : MBool = <Some = <True = {}> as Bool> as MBool in
19+
let Some_of_False : MBool = <Some = <False = {}> as Bool> as MBool in
20+
let None : MBool = <None = {}> as MBool in
21+
match None : MBool {
22+
<None = _ : {}> as MBool => <False = {}> as Bool,
23+
<Some = b : Bool> as MBool => b : Bool,
24+
}

rust-toolchain.toml

+2
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
[toolchain]
2+
channel = "nightly-2021-11-08"

rustfmt.toml

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
use_small_heuristics = "Max"

src/debruijn.rs

+28
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
#[derive(Debug, Copy, Clone, PartialEq, Eq, PartialOrd, Ord)]
2+
pub struct Debruijn {
3+
index: u64,
4+
}
5+
6+
impl Debruijn {
7+
pub const ZERO: Self = Self::new(0);
8+
9+
pub const fn new(index: u64) -> Self {
10+
Self { index }
11+
}
12+
13+
pub const fn index(self) -> u64 {
14+
self.index
15+
}
16+
17+
pub fn shift_by(mut self, by: u64) -> Self {
18+
self.index = self.index.checked_add(by).unwrap();
19+
self
20+
}
21+
}
22+
23+
impl std::fmt::Display for Debruijn {
24+
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
25+
let Self { index } = self;
26+
write!(f, "#{}", index)
27+
}
28+
}

0 commit comments

Comments
 (0)