HNHacker News
TopNewBestAskShowJobs

greyblake

115 karma · joined July 9, 2016

submissionscomments
greyblake··on No Human Error (Comic)
Short comic about AI systems and error handling.
greyblake··on Nutype (rust crate) 0.6.2 released
## What is nutype?

*nutype* is a procedural macro that adds sanitization and validation to newtypes, ensuring that values always meet your defined constraints.

## What’s new in v0.6.2

* *\[FEATURE]* Added `derive_unsafe(..)` for deriving arbitrary traits (requires enabling the `derive_unsafe` feature). * *\[FIX]* Upgraded Rust edition: *2021 → 2024*. * *\[FIX]* Improved error messages for `len_char_max` and `len_char_min`—they’re now clearer and easier to interpret.

## About `derive_unsafe`

With `derive_unsafe(..)`, you can now derive *any trait*, including third-party ones that nutype doesn’t recognize.

Unlike the safe `derive(..)`, this skips nutype’s internal checks. That means *you can accidentally break your validations at runtime*—for example, by enabling mutation via `DerefMut`.

To use this feature, add the `derive_unsafe` flag.

*Cautionary example:*

```rust use derive_more::{Deref, DerefMut}; use nutype::nutype;

#[nutype( derive(Debug, AsRef), derive_unsafe(Deref, DerefMut), validate(greater_or_equal = 0.0, less_or_equal = 2.0) )] struct LlmTemperature(f64);

fn main() { let mut temperature = LlmTemperature::try_new(1.5).unwrap();

    // This is exactly what you shouldn't do!
    *temperature = 2.5;

    // Validation rule? Violated.
    assert_eq!(temperature.as_ref(), &2.5);
} ```

*TL;DR:* `derive_unsafe` gives you freedom—but with that comes full responsibility. Use wisely.

greyblake··on [dead]
Nutype is a proc macro that allows adding extra constraints like sanitization and validation to the regular newtype pattern. The generated code makes it impossible to instantiate a value without passing the checks. It works this way even with serde deserialization.
greyblake··on From TypeScript to ReScript
CoffeeScript is a language without static typing. Despite this, CoffeeScript actually made a real revolution when it was introduced.
greyblake··on From TypeScript to ReScript
You don't have to. You can have write a single component in ReScript and use it with the rest of the project written in JS or TS. See https://rescript-lang.org/docs/gentype/latest/introduction
greyblake··on From TypeScript to ReScript
Whatlang demo webpage is implemented with seed: https://whatlang.org/
greyblake··on From TypeScript to ReScript
+1
greyblake··on From TypeScript to ReScript
There still "weak" points, where incorrect typing can be introduced, e.g. incorrectly written bindings. Regarding data from HTTP call in theory they can be cast to any type abusing `external` keyword which is meant for binings. But common and recommend approach is to write codes. Codec would perform all the necessary checks to ensure that the data are in correct shape to satisfy the type restrictions. You can see some examples here: https://github.com/greyblake/from-typescript-to-rescript/blo...
greyblake··on From TypeScript to ReScript
Because a programming language is not a template engine.
greyblake··on From TypeScript to ReScript
I agree, ReScript has no big adoption (hopefully yet), and that's the biggest disadvantage in comparison with TypeScript. But somebody has to do the first steps...
greyblake··on From TypeScript to ReScript
> the use of decorators in even the most basic example

Can we agree that JSX is not a valid JS? So decorators are required indeed to simulate "JSX magic"

> no async/await.

As I mentioned, it's not an really an issue (although I though it will be). At least from my experience.

> You can't have two files with the same name in different folders??

This sucks indeed :)

The problem that those 20% corrupt the value of another 80% :/

greyblake··on From TypeScript to ReScript
Thanks for your comment! I am aware of PureScript and even tried it a little bit 3-4 years ago, but was not aware that it has good interops too!