elipl/lib/tilly/bdd/string_bool_ops.ex
Kacper Marzecki 748f87636a checkpoint
checkpoint

failing test

after fixing tests

checkpoint

checkpoint

checkpoint

re-work

asd

checkpoint

checkpoint

checkpoint

mix proj

checkpoint mix

first parser impl

checkpoint

fix tests

re-org parser

checkpoint strings

fix multiline strings

tuples

checkpoint maps

checkpoint

checkpoint

checkpoint

checkpoint

fix weird eof expression parse error

checkpoint before typing

checkpoint

checpoint

checkpoint

checkpoint

checkpoint ids in primitive types

checkpoint

checkpoint

fix tests

initial annotation

checkpoint

checkpoint

checkpoint

union subtyping

conventions

refactor - split typer

typing tuples

checkpoint test refactor

checkpoint test refactor

parsing atoms

checkpoint atoms

wip lists

checkpoint typing lists

checkopint

checkpoint

wip fixing

correct list typing

map discussion

checkpoint map basic typing

fix tests checkpoint

checkpoint

checkpoint

checkpoint

fix condition typing

fix literal keys in map types

checkpoint union types

checkpoint union type

checkpoint row types discussion & bidirectional typecheck

checkpoint

basic lambdas

checkpoint lambdas typing application

wip function application

checkpoint

checkpoint

checkpoint cduce

checkpoint

checkpoint

checkpoint

checkpoint

checkpoint

checkpoint

checkpoint
2025-06-13 23:48:07 +02:00

88 lines
2.3 KiB
Elixir

defmodule Tilly.BDD.StringBoolOps do
@moduledoc """
BDD operations module for sets of strings.
Elements are strings, and leaf values are booleans.
"""
@doc """
Compares two strings.
Returns `:lt`, `:eq`, or `:gt`.
"""
def compare_elements(elem1, elem2) when is_binary(elem1) and is_binary(elem2) do
cond do
elem1 < elem2 -> :lt
elem1 > elem2 -> :gt
true -> :eq
end
end
@doc """
Checks if two strings are equal.
"""
def equal_element?(elem1, elem2) when is_binary(elem1) and is_binary(elem2) do
elem1 == elem2
end
@doc """
Hashes a string.
"""
def hash_element(elem) when is_binary(elem) do
# erlang.phash2 is suitable for term hashing
:erlang.phash2(elem)
end
@doc """
The leaf value representing an empty set of strings (false).
"""
def empty_leaf(), do: false
@doc """
The leaf value representing the universal set of strings (true).
"""
def any_leaf(), do: true
@doc """
Checks if a leaf value represents an empty set.
"""
def is_empty_leaf?(leaf_val) when is_boolean(leaf_val) do
leaf_val == false
end
@doc """
Computes the union of two leaf values.
`typing_ctx` is included for interface consistency, but not used for boolean leaves.
"""
def union_leaves(_typing_ctx, leaf1, leaf2) when is_boolean(leaf1) and is_boolean(leaf2) do
leaf1 or leaf2
end
@doc """
Computes the intersection of two leaf values.
`typing_ctx` is included for interface consistency, but not used for boolean leaves.
"""
def intersection_leaves(_typing_ctx, leaf1, leaf2)
when is_boolean(leaf1) and is_boolean(leaf2) do
leaf1 and leaf2
end
@doc """
Computes the negation of a leaf value.
`typing_ctx` is included for interface consistency, but not used for boolean leaves.
"""
def negation_leaf(_typing_ctx, leaf) when is_boolean(leaf) do
not leaf
end
# def difference_leaves(_typing_ctx, leaf1, leaf2) when is_boolean(leaf1) and is_boolean(leaf2) do
# leaf1 and (not leaf2)
# end
@doc """
Tests a leaf value to determine if it represents an empty, full, or other set.
Returns `:empty`, `:full`, or `:other`.
"""
def test_leaf_value(true), do: :full
def test_leaf_value(false), do: :empty
# def test_leaf_value(_other), do: :other
end