Open
Description
Describe the bug
NaN
and Infinity
are both Number
s, but Data.HugeNum.fromNumber
fails to parse them and throws an error.
To Reproduce
> import Data.HugeNum (fromNumber)
> import Data.Number (nan, infinity)
> fromNumber nan
file:///home/tom/frunco/.psci_modules/Data.Maybe/index.js:263
throw new Error("Failed pattern match at Data.Maybe (line 288, column 1 - line 288, column 46): " + [ v.constructor.name ]);
^
Error: Failed pattern match at Data.Maybe (line 288, column 1 - line 288, column 46): Nothing
at file:///home/tom/frunco/.psci_modules/Data.Maybe/index.js:263:15
at toString (file:///home/tom/frunco/.psci_modules/Data.HugeNum/index.js:173:18)
at showHugeNum.show (file:///home/tom/frunco/.psci_modules/Data.HugeNum/index.js:233:25)
at file:///home/tom/frunco/.psci_modules/Effect.Console/index.js:18:29
at file:///home/tom/frunco/.psci_modules/$PSCI/index.js:5:120
at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
Node.js v20.9.0
> fromNumber infinity
file:///home/tom/frunco/.psci_modules/Data.Maybe/index.js:263
throw new Error("Failed pattern match at Data.Maybe (line 288, column 1 - line 288, column 46): " + [ v.constructor.name ]);
^
Error: Failed pattern match at Data.Maybe (line 288, column 1 - line 288, column 46): Nothing
at file:///home/tom/frunco/.psci_modules/Data.Maybe/index.js:263:15
at toString (file:///home/tom/frunco/.psci_modules/Data.HugeNum/index.js:173:18)
at showHugeNum.show (file:///home/tom/frunco/.psci_modules/Data.HugeNum/index.js:233:25)
at file:///home/tom/frunco/.psci_modules/Effect.Console/index.js:18:29
at file:///home/tom/frunco/.psci_modules/$PSCI/index.js:5:120
at ModuleJob.run (node:internal/modules/esm/module_job:217:25)
at async ModuleLoader.import (node:internal/modules/esm/loader:316:24)
Expected behavior
fromNumber
should probably return a Maybe Number
instead.
Additional context
fromNumber
calls parseNumber
, which assumes that anything with type Number
can be a valid HugeNum
. parseNumber
is not exported or called by other functions, so it could be modified to return a Maybe NumberStyle
, using Data.Number.isFinite
to ensure the input is valid.