interface Embed a b where
embed : a -> b
Lossless injection: the source type fits inside the target. Nat embeds into Int because every Nat is a valid Int.
import nécessaire.interface Embed a b where
embed : a -> b
Lossless injection: the source type fits inside the target. Nat embeds into Int because every Nat is a valid Int.
interface Cast a b where
cast : a -> b
Potentially lossy conversion. Int casts to Double (no precision issue for small integers).
interface TryCast a b where
tryCast : a -> Maybe b
Conversion that may fail, returning Maybe. A negative Int cannot become a Nat.
isFinite : Double -> Bool
True for a Double with a genuine finite value — excludes NaN and ±Infinity. This is the representability test tryCast uses below: a finite Double is exactly the set of values truncate can turn into a faithful Int.
toInt : Nat -> Int
Convert a Nat to an Int (lossless).
natToInt : Nat -> Int
Convert a Nat to an Int (lossless) — toInt under the name the converse suggests (intToNat). natToInt 3 = 3.
toNat : Int -> Maybe Nat
Try to convert an Int to a Nat (fails if negative).
toDouble : Int -> Double
Convert an Int to a Double.
parseInt : String -> Maybe Int
Parse a signed decimal integer from a string; Nothing if it is not one. The SAFE counterpart of cast : String -> Double (which is total and lossy — it returns 0.0 on garbage). parseInt "42" = Just 42, parseInt "x" = Nothing, parseInt "3.5" = Nothing.
parseDouble : String -> Maybe Double
Parse a finite double from a string; Nothing if unparseable or non-finite (inf/nan). parseDouble "3.14" = Just 3.14, parseDouble "x" = Nothing.