From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on dcvr.yhbt.net X-Spam-Level: X-Spam-Status: No, score=-3.9 required=3.0 tests=BAYES_00, HEADER_FROM_DIFFERENT_DOMAINS,MAILING_LIST_MULTI,RCVD_IN_DNSWL_MED, SPF_HELO_NONE,SPF_PASS,UNPARSEABLE_RELAY shortcircuit=no autolearn=ham autolearn_force=no version=3.4.2 Received: from neon.ruby-lang.org (neon.ruby-lang.org [221.186.184.75]) by dcvr.yhbt.net (Postfix) with ESMTP id 063EB1FF9C for ; Mon, 26 Oct 2020 09:44:17 +0000 (UTC) Received: from neon.ruby-lang.org (localhost [IPv6:::1]) by neon.ruby-lang.org (Postfix) with ESMTP id 6F2B5120A74; Mon, 26 Oct 2020 18:43:37 +0900 (JST) Received: from xtrwkhkc.outbound-mail.sendgrid.net (xtrwkhkc.outbound-mail.sendgrid.net [167.89.16.28]) by neon.ruby-lang.org (Postfix) with ESMTPS id 3919A120A72 for ; Mon, 26 Oct 2020 18:43:35 +0900 (JST) Received: by filterdrecv-p3las1-bf7bc68d5-pcsdj with SMTP id filterdrecv-p3las1-bf7bc68d5-pcsdj-18-5F969A68-23 2020-10-26 09:44:08.63777362 +0000 UTC m=+402293.601223668 Received: from herokuapp.com (unknown) by ismtpd0034p1iad2.sendgrid.net (SG) with ESMTP id uPUTHGEBT02GKCdCA_uSaQ for ; Mon, 26 Oct 2020 09:44:08.510 +0000 (UTC) Date: Mon, 26 Oct 2020 09:44:08 +0000 (UTC) From: matsumoto@soutaro.com Message-ID: References: Mime-Version: 1.0 X-Redmine-MailingListIntegration-Message-Ids: 76440 X-Redmine-Project: ruby-master X-Redmine-Issue-Tracker: Feature X-Redmine-Issue-Id: 17265 X-Redmine-Issue-Author: marcandre X-Redmine-Issue-Assignee: matz X-Redmine-Sender: soutaro X-Mailer: Redmine X-Redmine-Host: bugs.ruby-lang.org X-Redmine-Site: Ruby Issue Tracking System X-Auto-Response-Suppress: All Auto-Submitted: auto-generated X-SG-EID: =?us-ascii?Q?3H9B9wKY1x1GeMVIOIuZAOOWFLruERfRz75gmtFq94qrQI48fecU5n1tH4zgZa?= =?us-ascii?Q?UYb+K2cv2dLOujbVvAj=2Flq46KeZ6RKOvwafBbVz?= =?us-ascii?Q?GV9UPJdFbS7CX0+7xW36quXSxlFa3ZJ6=2FjE6P9K?= =?us-ascii?Q?mlqwRxum9t7AJTRxwk9xwIf6hQ3p4qdnEL08GtT?= =?us-ascii?Q?0GG52ZZLPn5hILfI85o42V57cUfw8OG1iIIyDy7?= =?us-ascii?Q?U8i=2FTGTHW8J9hIB8E=3D?= To: ruby-core@ruby-lang.org X-Entity-ID: b/2+PoftWZ6GuOu3b0IycA== X-ML-Name: ruby-core X-Mail-Count: 100568 Subject: [ruby-core:100568] [Ruby master Feature#17265] Add `Bool` module X-BeenThere: ruby-core@ruby-lang.org X-Mailman-Version: 2.1.15 Precedence: list Reply-To: Ruby developers List-Id: Ruby developers List-Unsubscribe: , List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: quoted-printable Errors-To: ruby-core-bounces@ruby-lang.org Sender: "ruby-core" Issue #17265 has been updated by soutaro (Soutaro Matsumoto). I'm planning to make the semantics of `bool` in RBS (in the next release). = It will be an alias of `true | false` and we will add another type for cond= itionals, something like `type boolish =3D top`. So, I feel there is no strong reason from RBS side to add new class/module = to Ruby. ---------------------------------------- Feature #17265: Add `Bool` module https://bugs.ruby-lang.org/issues/17265#change-88200 * Author: marcandre (Marc-Andre Lafortune) * Status: Feedback * Priority: Normal * Assignee: matz (Yukihiro Matsumoto) ---------------------------------------- 1-line Summary: `rbs` would benefit from the existence of common ancestor `= Bool` for `TrueClass` and `FalseClass`. Detail: Matz: I am aware you rejected a similar request, but could we revisit this = in light of RBS? One use case was for an easy way to check for `true` or `false` values, ins= tead of simply for truthiness (e.g. for data transfer, strict argument chec= king, testing, etc.) I believe there's a new use case: `RBS` In `RBS`, the most used types like `String` and `Integer` have types for "s= tring-like" and "integer-like" objects: `string` and `integer` (all lowerca= se). For example the signature for `Integer#>>` is: ``` def >>: (int) -> Integer ``` It accepts an `Integer` *or an object responding to `to_int`* (summarized b= y `int`) and returns an `Integer` (and never another class of object respon= ding to `to_int` or not). There is a similar idea with boolean values, where a method may accept any = object and will use it's truthiness, while returning `true | false`. For ex= ample one of the interface for `Enumerable#all?` should look like: ``` def all?: () { (Elem) -> bool } -> true | false ``` The user supplied block can return any value, and its truthiness (anything = else than `nil` or `false`) will be used to determine the result of `all?`.= That result will be `true | false`, and no other value. If RBS is to be popular, there will be *many* signatures for such predicate= s (in builtin Ruby, stdlib, any gems, applications, etc.). I feel the best = option would be `Bool`, if this would be reflected in Ruby itself. Proposal: a new global module called `Bool`, without any method of constant= , included in `TrueClass` and `FalseClass`. Following reasons for rejection were given at the time: > many gems and libraries had already introduced Boolean class. I don't wan= t to break them. I looked and found the [`bool` gem](https://rubygems.org/gems/bool) that de= fines a `Bool` module. My proposal is compatible. In any case, this gem loo= ks abandoned, the author Aslak Helles=F8y doesn't have the code on github, = the gem has had 7000 downloads in the past 6 years and [has no public rever= se dependency](https://rubygems.org/gems/bool/reverse_dependencies). It als= o fails to install on my machine. I am not aware of incompatibilities. > `true` and `false` are the only representative of true-false values. In = Ruby. `nil` and `false` are falsy values, and everything else is a true val= ue. There's no meaning for having a superclass of `TrueClass` and `FalseCla= ss` as `Boolean`. The proposal is exactly to be able to easily write about this duality of `B= ool` as having only `true` and `false` as members, and every Ruby object as= being implicitly convertible as being truthy or falsy (`bool` in RBS). Discussion in RBS: * https://github.com/ruby/rbs/issues/133 Previous feature requests for `Boolean`: * https://bugs.ruby-lang.org/issues/14224 * https://bugs.ruby-lang.org/issues/12515 -- = https://bugs.ruby-lang.org/ Unsubscribe: