--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
you will handle the error case, and either come up with a sensible default, or tell your program to display some error message, or do something else to properly handle the error.
2. Runtime Exception. Like a NullPointerException or an IllegalArgumentException. I love these kind of bugs. Super easy to find. Super easy to fix. A stack trace tells me exactly where to look. These kind of exceptions have never been a thorn in my spine.
Duane. Don't get me wrong. I prefer compile errors over runtime errors. And if Elm can catch more errors at compile time without adding a bunch of noise to my code that is a good thing obviously.
But runtime errors are unavoidable. It's not possible for the compiler to catch every possible error condition. The question is, does the language have an elegant mechanism to deal with runtime exceptions? Especially in a separate flow from the normal return value.
And from what I am hearing the answer is either no or no one is telling me what it is.
So my question is: does Elm have something similar to throw/raise?
--
You received this message because you are subscribed to a topic in the Google Groups "Elm Discuss" group.
To unsubscribe from this topic, visit https://groups.google.com/d/topic/elm-discuss/00CgYDiMvBI/unsubscribe.
To unsubscribe from this group and all its topics, send an email to elm-discuss+unsubscribe@googlegroups.com.
To unsubscribe from this group and all its topics, send an email to elm-discuss...@googlegroups.com.
So, based on my understanding, the whole "no runtime exceptions" concept is just not computing.But I am new to Elm. Surely I am misunderstanding something. Please tell me what I am missing.
--
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...@googlegroups.com.
This means that there is no exception that will bubble up unhandled at runtime and crash your app.
--
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+unsubscribe@googlegroups.com.
Runtime exceptions are inevitable
I could do Maybe and Result in C.
Theoretically of course, Elm doesn't solve the halting problem and you can always blow the stack or exhaust memory. So it's not terrible that any function can call Debug.crash, which is an uncatchable exception. It's useful for when you think something can never, ever, happen.
But exception bubbling is a feature. An extremely useful feature. Language level support for exceptions has been a staple of every programming language since C. I do not consider Maybe and Result to be a useful substitute for language level exception support. I could do Maybe and Result in C.
Runtime exceptions are inevitable
You can keep saying it, but it doesn't make it true.
If you can come up with a practical scenario where you would have an exception, I or someone else around here could tell you what would happen in Elm in that context.
Finally, you do have the option of crashing the entire program with Debug.crash
Then at the edge of the application, I can deal with the errors
On Fri, Oct 7, 2016 at 11:10 AM, Peter Damoc <pda...@gmail.com> wrote:If you can come up with a practical scenario where you would have an exception, I or someone else around here could tell you what would happen in Elm in that context.Yes. The example I gave when I started the thread (sorry for the java syntax - i'm new):function foo(int x) throws IllegalArgumentException{if(x > 10) throw new IllegalArgumentException("Bad x");return x * x * x;}
| type Either a b | |
| = Left a | |
| | Right b |
7 окт. 2016 г., в 4:48, Dave Ford <df...@smart-soft.com> написал(а):
--
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...@googlegroups.com.
Do not use Either. The Result type in the standard library is the same, but with the names more intuitive.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss+unsubscribe@googlegroups.com.
--
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+unsubscribe@googlegroups.com.
Promise.resolve(myValue) ~= Ok myValue
Promise.reject(myErrorData) ~= Err myErrorData
promise.then(fn) ~= myResult.andThen(fn) or myResult.map(fn)
promise.catch(fn) ~= case myResult of Err x -> fn x--
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+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.
void myFunction(int x){if(x < 1){throw new IllegalArgumentException("error: x must be >= 1");}return x * x * x;}I look at runtime exceptions as a good thing. It's kind of like having two returns. One return for the normal answer (return). And another for error conditions (throw).
myFunction : Int -> Result String Int
myFunction =
if x < 1 then
Err "x must be >= 1"
else
Some x * x * x
errorResult : Result String Int
errorResult = Result.map (myFunction) (myFunction 0)
-> Err "x must be >= 1"
okResult : Result String Int
okResult = Result.map (myFunction) (myFunction 2)
-> Some 64