On Tuesday, February 21, 2017 at 11:43:49 AM UTC, Jakub Hampl wrote:
>
> If you have such a case where correctness is much more important than 
> ergonomics, nothing is stopping you from creating your own type that 
> performs maths safely and using it through out your app. 
>

Or without creating my own type, just create a library of 'safe' math 
functions:

div a b = 
  if b == 0 then
   Nothing
  else
   Just (a // b)

or some such.

I have a text file on my Desktop and every time I see things that are 
missing or not made explicit in Elm documentation I add a note to this file 
with the eventual plan of contributing back some missing docs - I think 
there should be some kind of warning in the docs about the incorrectness of 
the built in math functions until such time as better long term solutions 
are worked out for them.

Another thing to note is that as Ints are represented as javascript 
numbers, which are single precision floating point, that makes them 56 bits 
wide. Very weird when most languages default to 32 or 64.

Also database ids might often be 64 bits, but not very often overflow 56 
bits, catching out the unwary. I wonder if anyone ever uses a database 
sequence that counts down from 2^64-1 rather than up from 1, to try and 
flush these problems out early. I just generally treat any kind of id as an 
opaque string in Elm, but even that won't solve the problem - I think the 
JSON passed from the server might put numerical ids in without quotes 'id : 
2334' and Decode.string won't accept something without quotes as a String, 
so I first parse it as an Int then convert to a String.

-- 
You received this message because you are subscribed to the Google Groups "Elm 
Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to