On Saturday, February 18, 2017 at 9:53:49 PM UTC, Erkal Selman wrote:
>
> Why didn't you try it?
> Try it!
> Yes, it returns Infinity.
> Would you that error handling for every other operation, like for example
> the squareroot of negative numbers, or the logarithm of zero? I don't think
> that this is a good idea for a language like elm.
>
With elm-repl:
> type alias T = { val : Int }
> t = T 4
{ val = 4 } : Repl.T
> x = t.val / 0
-- TYPE MISMATCH ---------------------------------------------
repl-temp-000.elm
The left argument of (/) is causing a type mismatch.
8| t.val / 0
^^^^^
(/) is expecting the left argument to be a:
Float
But the left argument is:
Int
Hint: Elm does not automatically convert between Ints and Floats. Use
`toFloat`
and `round` to do specific conversions.
<http://package.elm-lang.org/packages/elm-lang/core/latest/Basics#toFloat>
Hint: The (/) operator is specifically for floating point division, and
(//) is
for integer division. You may need to do some conversions between ints and
floats to get both arguments matching the division operator you want.
> x = t.val // 0
0 : Int
>
So for integer division by zero, it simply returns zero!
--
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.