I think for integer division, it has to return 0 because infinity is
expressed as a float. I'm going to agree with Erkal, though, you definitely
don't want to wrap all your math statements in a maybe or result type, that
would make most code considerably more verbose.

On Sat, Feb 18, 2017 at 5:38 PM, 'Rupert Smith' via Elm Discuss <
elm-discuss@googlegroups.com> wrote:

> 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 elm-discuss+unsubscr...@googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>

-- 
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 elm-discuss+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to