Gluon: Expose wrapping and saturating arithmetic for integer and bytes

Created on 22 Oct 2018  路  5Comments  路  Source: gluon-lang/gluon

All 5 comments

I think I can find some time for this this evening.

I think in the long run I'd like to have custom implicit instances of Num for num, but I am pretty sure that it won't work out unless there is a way to pull in implicit instance and override one that is already in scope. Since Byte and Int always have the normal Num Int/Num Byte in scope a adding wrapping or saturating instance in scope will always cause ambiguities.

```f#
// Normal Num Int
let { ? } = import! std.int

1 + 2 // OK
let { ? } = (import! std.int).wrapping
1 + 2 // Error ambigous

[override]

let { ? } = (import! std.int).wrapping
1 + 2 // Ok since wrapping is selected
```

I think in the long run I'd like to have custom implicit instances of Num for num, but I am pretty sure that it won't work out unless there is a way to pull in implicit instance and override one that is already in scope.

Yeah, that seems really useful. I'm a bit torn on this, on one hand I actually like the explicitness of using a different function, on the other I can see how this would be really annoying when you are using it a lot. I guess this is just a thing where you have to be careful and only introduce the new binding in a new scope, so it doesn't override the behaviour of (+) half way through the file.

By the way, I just noticed that currently VmInt is defined as isize, but according to the gluon std docs it's always a i64. The alias should probably just be i64 then (it will be on most systems anyway).

By the way, I just noticed that currently VmInt is defined as isize, but according to the gluon std docs it's always a i64. The alias should probably just be i64 then (it will be on most systems anyway).

Yeah that's #403 . Should just stabilize on i64

Was this page helpful?
0 / 5 - 0 ratings

Related issues

typesanitizer picture typesanitizer  路  12Comments

Marwes picture Marwes  路  10Comments

jrpascucci picture jrpascucci  路  6Comments

Shuenhoy picture Shuenhoy  路  4Comments

brendanzab picture brendanzab  路  15Comments