<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kiyoshi Mizumoto</title>
    <description>The latest articles on DEV Community by Kiyoshi Mizumoto (@mizumotok).</description>
    <link>https://dev.to/mizumotok</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F3983323%2Fa4806d65-e565-4bee-a93a-783c4eda21a6.png</url>
      <title>DEV Community: Kiyoshi Mizumoto</title>
      <link>https://dev.to/mizumotok</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/mizumotok"/>
    <language>en</language>
    <item>
      <title>Why `Float` Has No `==` in Tyra</title>
      <dc:creator>Kiyoshi Mizumoto</dc:creator>
      <pubDate>Sun, 14 Jun 2026 02:40:55 +0000</pubDate>
      <link>https://dev.to/tyra-lang/why-float-has-no-in-tyra-3339</link>
      <guid>https://dev.to/tyra-lang/why-float-has-no-in-tyra-3339</guid>
      <description>&lt;p&gt;When you write &lt;code&gt;1.0 == 1.0&lt;/code&gt; in Tyra, you get a compile error.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;error[E0305]: Float does not satisfy the Eq ability
  --&amp;gt; src/main.ty:3:8
   |
 3 |   if a == 1.0
   |        ^^ Float has no Eq
   |
   = help: use float.eq(a, 1.0) for IEEE 754 equality,
           or float.approx_eq(a, b, epsilon: 1e-9) for tolerance comparison
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is intentional. Here's why.&lt;/p&gt;




&lt;h2&gt;
  
  
  The NaN problem
&lt;/h2&gt;

&lt;p&gt;IEEE 754 — the floating-point standard every language uses — defines that &lt;code&gt;NaN != NaN&lt;/code&gt;. Always. No exceptions.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Python
&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;nan&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;  &lt;span class="c1"&gt;# False
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;





&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight go"&gt;&lt;code&gt;&lt;span class="c"&gt;// Go&lt;/span&gt;
&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;:=&lt;/span&gt; &lt;span class="n"&gt;math&lt;/span&gt;&lt;span class="o"&gt;.&lt;/span&gt;&lt;span class="n"&gt;NaN&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;==&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;  &lt;span class="c"&gt;// false&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This rule exists for numerical computing reasons (NaN propagation semantics), but it breaks one of the most fundamental assumptions in programming: &lt;strong&gt;any value equals itself&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In every language that gives &lt;code&gt;Float&lt;/code&gt; a standard equality operator, you have a class of values called &lt;strong&gt;reflexivity-breaking values&lt;/strong&gt;: things where &lt;code&gt;a == a&lt;/code&gt; is false. Most programmers don't think about this until they hit a bug.&lt;/p&gt;




&lt;h2&gt;
  
  
  What breaks when Float has Eq
&lt;/h2&gt;

&lt;h3&gt;
  
  
  Structural equality on compound types
&lt;/h3&gt;

&lt;p&gt;Tyra has &lt;code&gt;value&lt;/code&gt; types — immutable record types that get structural equality: two &lt;code&gt;Point&lt;/code&gt;s are equal if all their fields are equal.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;value Point
  x: Float
  y: Float
end
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If &lt;code&gt;Float&lt;/code&gt; had &lt;code&gt;Eq&lt;/code&gt;, Tyra would auto-derive &lt;code&gt;Eq&lt;/code&gt; for &lt;code&gt;Point&lt;/code&gt;. But then:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;let p = Point(x: 0.0 / 0.0, y: 1.0)  # x is NaN
p == p  # What should this return?
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;IEEE 754 says &lt;code&gt;NaN != NaN&lt;/code&gt;, so field-by-field comparison gives &lt;code&gt;false&lt;/code&gt;.&lt;br&gt;
Structural equality says two identical objects are equal, so it should be &lt;code&gt;true&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;These two invariants cannot both hold. Pick one and you're lying to the programmer about the other.&lt;/p&gt;
&lt;h3&gt;
  
  
  Hash maps and sets
&lt;/h3&gt;

&lt;p&gt;In Python and JavaScript, using a float as a dictionary key works until it doesn't:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="n"&gt;d&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="p"&gt;{}&lt;/span&gt;
&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;nan&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;1&lt;/span&gt;
&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="nf"&gt;float&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;nan&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)]&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;2&lt;/span&gt;
&lt;span class="nf"&gt;len&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;d&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;  &lt;span class="c1"&gt;# 2 — two different NaN keys!
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This happens because &lt;code&gt;hash(nan) == hash(nan)&lt;/code&gt; but &lt;code&gt;nan != nan&lt;/code&gt;, so two NaN keys are considered distinct. The HashMap contract (&lt;code&gt;a == b&lt;/code&gt; implies &lt;code&gt;hash(a) == hash(b)&lt;/code&gt;) is violated silently.&lt;/p&gt;

&lt;p&gt;In Tyra, &lt;code&gt;Map&amp;lt;Float, V&amp;gt;&lt;/code&gt; is a &lt;strong&gt;compile error&lt;/strong&gt;. The bug class doesn't exist.&lt;/p&gt;




&lt;h2&gt;
  
  
  The three ways to handle this
&lt;/h2&gt;

&lt;p&gt;Every language with a static type system faces this problem. The mainstream options:&lt;/p&gt;

&lt;h3&gt;
  
  
  Option 1: IEEE 754 semantics (most languages)
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Float == Float&lt;/code&gt; works, &lt;code&gt;NaN != NaN&lt;/code&gt;. Reflexivity breaks for NaN values.&lt;/p&gt;

&lt;p&gt;This is what C, Java, JavaScript, Python, and Go do. It's pragmatic and familiar, but it leaks IEEE 754 semantics into the equality abstraction. Bugs involving NaN are notoriously hard to trace.&lt;/p&gt;

&lt;h3&gt;
  
  
  Option 2: Two-tier equality (Rust)
&lt;/h3&gt;

&lt;p&gt;Rust splits the concept: &lt;code&gt;PartialEq&lt;/code&gt; means "might not be reflexive" (Float qualifies), &lt;code&gt;Eq&lt;/code&gt; means "always reflexive" (Float does not).&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight rust"&gt;&lt;code&gt;&lt;span class="c1"&gt;// Rust: Point derives PartialEq but NOT Eq&lt;/span&gt;
&lt;span class="nd"&gt;#[derive(PartialEq)]&lt;/span&gt;
&lt;span class="k"&gt;struct&lt;/span&gt; &lt;span class="n"&gt;Point&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;f64&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="nb"&gt;f64&lt;/span&gt; &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;This is honest and precise, but it adds complexity. &lt;code&gt;PartialEq&lt;/code&gt; vs &lt;code&gt;Eq&lt;/code&gt; is one of Rust's most confusing distinctions for beginners — two equality traits, two sets of bounds in generics, two different things to explain.&lt;/p&gt;

&lt;h3&gt;
  
  
  Option 3: No Eq for Float (Tyra)
&lt;/h3&gt;

&lt;p&gt;&lt;code&gt;Float&lt;/code&gt; simply does not satisfy &lt;code&gt;Eq&lt;/code&gt;. The operator &lt;code&gt;==&lt;/code&gt; is only available for types that provably satisfy reflexivity.&lt;/p&gt;

&lt;p&gt;Explicit comparison functions are available:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;import float

float.eq(a, b)                        # IEEE 754: NaN != NaN, 0.0 == -0.0
float.approx_eq(a, b, epsilon: 1e-9)  # tolerance comparison
float.is_nan(a)                        # explicit NaN check
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;






&lt;h2&gt;
  
  
  Why this is the right tradeoff for Tyra
&lt;/h2&gt;

&lt;p&gt;Tyra's target domain is &lt;strong&gt;web backends, CLI tools, and business applications&lt;/strong&gt; — not scientific computing or graphics engines. In that domain:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Money should be &lt;code&gt;Int&lt;/code&gt; (cents), never &lt;code&gt;Float&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;JSON numbers that need exact comparison are usually integers&lt;/li&gt;
&lt;li&gt;The legitimate use cases for float equality are rare and should be explicit&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The error message points you to the right function. The type system forces you to think about what kind of float comparison you actually want — not just reach for &lt;code&gt;==&lt;/code&gt; and hope NaN never shows up.&lt;/p&gt;




&lt;h2&gt;
  
  
  What this enables: AI-friendly design
&lt;/h2&gt;

&lt;p&gt;One of Tyra's goals is to be a language where LLMs generate correct code on first try, without debugging cycles. Float equality traps are a significant source of subtle bugs in LLM-generated code. The model writes &lt;code&gt;a == b&lt;/code&gt; because that's the pattern it learned from Python and JavaScript. The Tyra compiler rejects it and explains the alternative.&lt;/p&gt;

&lt;p&gt;In our benchmark (100 tasks, Claude generating code from the language spec), Tyra achieves an &lt;strong&gt;88.7% mean pass rate across 3 seeds&lt;/strong&gt;. This exceeds Go's existing seed-1 point estimate (81%), though the two figures use different methodologies so a same-condition comparison is still pending. Design choices like this one — where the type system catches a common bug class before the test runner does — are consistent with that result.&lt;/p&gt;




&lt;h2&gt;
  
  
  The ability system
&lt;/h2&gt;

&lt;p&gt;For those unfamiliar with Tyra: &lt;strong&gt;abilities&lt;/strong&gt; are Tyra's type classes. They work like Rust traits or Haskell type classes, but the name distinguishes them from Tyra's &lt;code&gt;trait&lt;/code&gt; keyword, which is the mechanism for interface polymorphism — a separate concept.&lt;/p&gt;

&lt;p&gt;The four core abilities are &lt;code&gt;Eq&lt;/code&gt;, &lt;code&gt;Hash&lt;/code&gt;, &lt;code&gt;Ord&lt;/code&gt;, and &lt;code&gt;Debug&lt;/code&gt;. Auto-derivation works by structural inspection: a &lt;code&gt;value&lt;/code&gt; or &lt;code&gt;data&lt;/code&gt; type gets &lt;code&gt;Eq&lt;/code&gt; automatically if and only if all its fields satisfy &lt;code&gt;Eq&lt;/code&gt;. Since &lt;code&gt;Float&lt;/code&gt; doesn't satisfy &lt;code&gt;Eq&lt;/code&gt;, no type containing a &lt;code&gt;Float&lt;/code&gt; field gets &lt;code&gt;Eq&lt;/code&gt; for free.&lt;/p&gt;

&lt;p&gt;This propagation rule is intentionally simple and consistent: no exceptions, no special cases. One rule covers everything.&lt;/p&gt;




&lt;h2&gt;
  
  
  The tradeoff is real
&lt;/h2&gt;

&lt;p&gt;I'm not going to pretend there's no cost. Writing &lt;code&gt;float.approx_eq(result, expected, epsilon: 1e-9)&lt;/code&gt; in a test is more verbose than &lt;code&gt;result == expected&lt;/code&gt;. If you're writing numerical algorithms, the absence of &lt;code&gt;==&lt;/code&gt; on floats is genuinely inconvenient.&lt;/p&gt;

&lt;p&gt;But the alternative is a category of bugs that are hard to find, hard to name, and hard to explain — to a reviewer, a type checker, or an LLM. Tyra trades some verbosity to eliminate the bug class entirely.&lt;/p&gt;

&lt;p&gt;If you're building the next numerical solver or game engine, Tyra is probably not your language. If you're building a web API or a CLI tool, float equality probably isn't something you need — and if you do need it, the error message tells you exactly what to use instead.&lt;/p&gt;




&lt;p&gt;&lt;em&gt;Tyra is an open-source, Ruby-inspired language that compiles to native binaries via LLVM.&lt;br&gt;
Source: &lt;a href="https://github.com/tyra-lang/tyra" rel="noopener noreferrer"&gt;github.com/tyra-lang/tyra&lt;/a&gt; — feedback welcome.&lt;/em&gt;&lt;/p&gt;

</description>
      <category>coding</category>
      <category>computerscience</category>
      <category>programming</category>
    </item>
  </channel>
</rss>
