TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

A Gentle Introduction to Liquid Types

138 pointsby marvinbornerover 1 year ago

13 comments

one-punchover 1 year ago
Liquid Types enabled a 6x speed up in high-performance parsing of UDP packets, according to &quot;Scrap your Bounds Checks with Liquid Haskell&quot; of Gabriella Gonzalez [1].<p>With Liquid Haskell, the bound checks are moved from runtime to compile time, semi-automatically handled by SMT-solvers. Static types help programmers to write correct programs faster, and the programs also run faster.<p>As an aside, speeding up programs with static analysis (constrained dynamism) are also present in Mojo (a variant of Python) or Swift [2].<p>[1]: <a href="https:&#x2F;&#x2F;github.com&#x2F;Gabriella439&#x2F;slides&#x2F;blob&#x2F;main&#x2F;liquidhaskell&#x2F;slides.md">https:&#x2F;&#x2F;github.com&#x2F;Gabriella439&#x2F;slides&#x2F;blob&#x2F;main&#x2F;liquidhaske...</a> &quot;Scrap your Bounds Checks with Liquid Haskell&quot;<p>[2]: <a href="https:&#x2F;&#x2F;github.com&#x2F;modularml&#x2F;mojo&#x2F;discussions&#x2F;466">https:&#x2F;&#x2F;github.com&#x2F;modularml&#x2F;mojo&#x2F;discussions&#x2F;466</a> &quot;Mojo and Dynamism&quot;
评论 #37376946 未加载
评论 #37376791 未加载
评论 #37376603 未加载
skybrianover 1 year ago
An important thing to remember about fancy type systems is that they can only make guarantees in a closed world. If your data comes from the network or a file, you will likely need a reader or parser that does runtime checks somewhere, but a good type system can provide assurance that you did each check exactly once.<p>On a complicated single-process system (a monolith), that can be a big improvement. For distributed systems (microservices), there will still be plenty of runtime checks. That&#x27;s what allows each service to have its own lifecycle.<p>I&#x27;m wondering what Elixir will do, given that Erlang servers divide up work into lots of independent, distributed components?
评论 #37377431 未加载
评论 #37378900 未加载
评论 #37378078 未加载
A_D_E_P_Tover 1 year ago
I honestly thought that this was going to be about actual liquid types -- from the regular ones that (macroscopically) differ largely in terms of viscosity, to non-Newtonian liquids which have non-linear viscosity characteristics, to long-chain (PEG-type) polymers that have slightly unusual flow characteristics, to superfluids that have extremely weird characteristics and zero viscosity.<p>...I&#x27;d read that article. Now I&#x27;m starting to think that I should write it.
评论 #37377088 未加载
评论 #37384696 未加载
hansvmover 1 year ago
This sort of idea is why I sketched out pdv [0] in Zig. Even extremely simple type systems can handle arbitrary invariants when you are allowed to compute with those invariants at compile time.<p>[0] <a href="https:&#x2F;&#x2F;github.com&#x2F;hmusgrave&#x2F;pdv">https:&#x2F;&#x2F;github.com&#x2F;hmusgrave&#x2F;pdv</a>
评论 #37550817 未加载
quickthrower2over 1 year ago
I like this sort of idea for typifying dynamic languages (like JS)<p>What if instead of TS, you had plain JS as-is (no compiler needed!) then just add comment like:<p><pre><code> &#x2F;* x is an integer, x &gt; 0 ... *&#x2F; function add(x, y) { ... </code></pre> Sorry the example ain&#x27;t great but the point is that you can be precise with refinement types. I think refinement types (less all the mathy explanations) are more intuitive. They would be like assertions or C# code contracts. The content of those types would look &quot;business-ey&quot; rather than &quot;category theory-ish&quot;.
评论 #37376357 未加载
__vec__over 1 year ago
DML link in the article is broken - Might I instead point you to a relevant ATS-lang (successor<i>2 of DML) documentation about `Dependent Types in ATS2` <a href="https:&#x2F;&#x2F;ats-lang.sourceforge.net&#x2F;DOCUMENT&#x2F;INTPROGINATS&#x2F;HTML&#x2F;c2100.html" rel="nofollow noreferrer">https:&#x2F;&#x2F;ats-lang.sourceforge.net&#x2F;DOCUMENT&#x2F;INTPROGINATS&#x2F;HTML&#x2F;...</a><p>This link discusses, along with other usefulness, the use of dependent types for the likes of array bounds checking, creating &quot;sorts&quot; of numbers satisfying various predicates, and more interestingly the utility of combining Dependent Types with PURE Linear Types (as opposed to Affine Types a la Rust lol) ...<p>AFAIK, DML was originally intended as a gateway to constructing typed assembly (DARPA)<p>Having been a researcher in this field for, this quote from the original paper on &#x27;Liquid Types&#x27; originally seemed suspect.... &quot;a system that combines Hindley-Milner type inference with Predicate Abstraction to automatically infer dependent types precise enough to prove a variety of safety properties&quot; .... type inference with dependent types is undecidable!? Then again, this is one of the primary focuses of ATS3, I digress...<p>This area of research is rich in pipe-dreams and cerebral investigation. From my biased opinion, ATS3 (the current version of the successor</i>3 of DML, being actively devloped by the PI Professor Hongwei Xi, is the only language in this space to be aimed at practical programming in industry... of course there is always haskell....)<p>What I mean is that, TEMPLATES++ Linear Types + Dependent Types + Hindley Milner Type inference ....<p>At the end of the day, who doesn&#x27;t love hyper efficient meta-programming magic?
评论 #37377085 未加载
richard_feyover 1 year ago
How do you define operations on these liquid types? You can&#x27;t even define subtraction or addition on this &quot;non zero integer type&quot;. These types are not closed so how is it useful?
评论 #37377525 未加载
评论 #37377125 未加载
LeanderKover 1 year ago
I wonder how pragmatic those can become. Usually I don&#x27;t really care about &quot;exact&quot; exactness, a common theme in haskell. A sort of &quot;under common assumptions&quot; (no underflow&#x2F;overflow&#x2F;OOM etc.) proof of laws and properties. This eliminates a whole class of bugs and strengthens your ability to reason, but doesn&#x27;t make everything super, super complicated by thinking about all those edge cases.<p>One usually doesn&#x27;t program airplane control software. Some bugs are okay and speed of development and correctness is a trade-off.
mabboover 1 year ago
I wonder what is possible in more common languages like Java or Python.<p>Certainly, the language itself won&#x27;t have liquid types in the compiler any time soon. But taking Ruby&#x27;s Sorbet as inspiration, I wonder if you could annotate Java classes with semantic rules and do some simple verifications as a post-compilation step?<p>There&#x27;s too much bad code out there that can&#x27;t just be replaced. Tools to help make it better would be a huge boon.
评论 #37385619 未加载
评论 #37380475 未加载
dionianover 1 year ago
reminds me a little of eiffel&#x27;s design by contract. it looks really promising
评论 #37376115 未加载
评论 #37378341 未加载
eithedover 1 year ago
If Int (without 0) should be used, why not use IntWithoutZero type?
everybodyknowsover 1 year ago
Title needs to append (2015).
peepeepoopoo33over 1 year ago
Programming language design took a wrong turn with these extremely complicated type systems. They end up hurting developer productivity, and you spend more time fiddling with types than solving the problem at hand. We should be focusing on more effective forms of abstraction instead of types.
评论 #37375698 未加载
评论 #37375819 未加载
评论 #37375694 未加载
评论 #37376715 未加载
评论 #37378915 未加载
评论 #37375637 未加载
评论 #37375743 未加载