Macaulay2 / Macaulay2/M2

Allow truthiness for types

Open
#3,229 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Interpreter
Dominant language
Macaulay2
Stars
435
Forks
297
Avg merge
4d 20h
Merged PRs (30d)
11

Description

I'll explain via an example:

i1 : Truthy = new Type of List;

i2 : Truthy == Boolean := (T, B) -> T#0 === B;

i3 : T = new Truthy from {true}

o3 = {true}

o3 : Truthy

i4 : F = new Truthy from {false}

o4 = {false}

o4 : Truthy

Given such a type, it would be desirable to use it in if .. then .. else .. clauses, but this fails:

i5 : if T then print "true"
stdio:5:4:(3): error: expected true or false

Even though this works fine:

i6 : T == true

o6 = true

i8 : T == false

o8 = false

We can define binary operations fine:

i9 : not Truthy := T -> new Truthy from {not T#0};

i10 : not T

o10 = {false}

o10 : Truthy

i17 : Truthy and Truthy := (T1, T2) -> new Truthy from {T1#0 and T2#0};

i18 : T and F

o18 = {false}

o18 : Truthy

i19 : T and T

o19 = {true}

o19 : Truthy

One solution is having if and while clauses evaluate truthiness using a method that can be installed from the top level.

One application of this is having lazily evaluated predicates and binary operations that take advantage of this, or even basic symbolic logic.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by locating the implementation of if and while condition evaluation, then trace how conditions are restricted to true or false. Use the Truthy examples in the issue to define tests; done means user-defined truthiness works in both clauses without breaking existing Boolean behavior.

Written by the indexing model from the issue text.

Assessment

Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Needs clarification
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.