Re: [elm-discuss] Re: No Runtime Exceptions - Still not computing

2016-10-08 Thread Zachary Kessin
Putting on my  Erlang Developer hat (Moto: Let it Crash) I look at it this
way there are two kinds .of errors, normal errors an exceptional errors.
Lets say you want to go to the store to buy a dozen eggs. There are a few
possible outcomes here

1) You get the eggs
2) You can't buy the eggs (Store is out of stock/ no money etc)
3) You can't get to the store because of some kind of Force Major. (IE The
store burned down, the police have blocked the street due to an abandoned
bag etc)

The elm type system with a Maybe / Result will handle cases #1 and #2. As
for case 3, that is a little harder but can still be handled.

Or to take your examples


   - Invalid function args
   - Malformed JSON
   - Server down

The first one will be handled by the type system. If you try to pass an
invalid argument to a function the code will not compile. Obviously there
are ways to take run time data and test for validity. You can imagine a
function like "parseRomanNumeral : String -> Maybe Int" which takes a
string and attempts to treat it as a roman numeral. But the Maybe is there
for the case where its not.

As for the Malformed JSON then you have enforced error handling code.

In the case of a server down. (As Joe Armstrong said "The best type system
will not prevent your server from being struck by lightning" ). Then you
get a timeout error which you can handle in some useful way




ᐧ

On Sat, Oct 8, 2016 at 5:03 PM, Martin Janiczek  wrote:

> Dave, how do you think about JavaScript Promises? Where you code for the
> happy path (the chain of Promise.resolve().then().then().then()), any of
> which can throw, and have a .catch() handler that catches whatever the
> thrown value was and does something about it.
> The Elm Result type is very similar to this.
>
> 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
>
>
> Again, a specific example would help. Elm programs are not written the way
> C, C#, Java programs are written. Clojure is closer but because of Java
> interop reasons hasn't adopted much of the Maybe / Result / ... goodness
> and instead has nils like Java has. In Elm the erorrs are explicit (like
> you say, part of the return type). Read: http://blog.jenkster.
> com/2016/06/how-elm-slays-a-ui-antipattern.html for how Elm solves the
> Server Down error you mentioned.
>
> Malformed JSON is also reported not with exceptions but with Result.
> Either you get your value in Ok, or helpful error message in Err. You have
> to handle both cases, it doesn't propagate up, it doesn't throw a runtime
> exception, the user sees what you decided to show him in that scenario.
> Essentially the Elm compiler tells you "This could blow up - you told me
> what to do if the JSON is OK, but what if it is not?"
>
> On Friday, October 7, 2016 at 10:05:50 PM UTC+2, Dave Ford wrote:
>>
>>
>>
>> On Fri, Oct 7, 2016 at 11:33 AM, Kasey Speakman 
>> wrote:
>>>
>>> Then at the edge of the application, I can deal with the errors
>>>
>> Yes. This is what I am trying to figure out. How to deal with that class
>> of errors at the "edge".
>>
>> Thanks.
>>
>> --
> 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.
>



-- 
Zach Kessin
SquareTarget 
Twitter: @zkessin 
Skype: zachkessin

-- 
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.


Re: [elm-discuss] Re: Creating an API to be consumed by JS developers

2016-10-08 Thread Dave Ford
That's pretty much how GWT was.

On Sat, Oct 8, 2016 at 1:34 PM, OvermindDL1  wrote:

> The 'official' interaction between Elm and javascript is via ports, which
> involves marshelling any JSON-compatible type across the interface.  From
> the Javascript side it involves just 'send'ing something to somewhere (like
> via `Elm.MyApp.ports.someport.send("something");`) or to get data from
> Elm you 'subscribe' to it (such as in `Elm.MyApp.ports.someport.
> subscribe(function(msg){console.log(msg);})`).  It defines a specific
> interface for data to transfer over so everything on the Elm side can be
> 'safe' and any unsafe access happens only through know access points.
>
>
> On Saturday, October 8, 2016 at 12:22:12 PM UTC-6, Dave Ford wrote:
>>
>> My experience with compile-to-js languages include: GWT, Dart and
>> TypeScript.
>>
>> GWT was very good at *calling* JS libraries. Almost zero friction. But
>> not so, in the other direction. Creating API's to be consumed by JS was so
>> ugly that I can confidently say that it was not worth it. Unless you are
>> creating an API that has a very small surface area to functionality ration
>> (like maybe a spell checker).
>>
>> Dart has a similar story to GWT.
>>
>> By far the best inter-op story is TypeScript. If you write a lib
>> in TypeScript it can be consumed by JS as-is. No special anything is
>> needed.
>>
>> So my question is, where does Elm fall in this spectrum. Is it advisable
>> to create an api in Elm to be consumed by JS developers?
>>
> --
> 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/Rw3dPPgaRRI/unsubscribe.
> To unsubscribe from this group and all its topics, 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.


Re: [elm-discuss] Maybe.andThen with List.foldr type trick?

2016-10-08 Thread Duane Johnson
Ah, I misunderstood the order of foldr. Thanks alll.

BTW, this helped me see where I'd gone wrong:
http://stackoverflow.com/questions/1757740/how-foldr-works#1763323

On Sat, Oct 8, 2016 at 10:09 AM, Janis Voigtländer <
janis.voigtlaen...@gmail.com> wrote:

> http://package.elm-lang.org/packages/elm-community/maybe-
> extra/2.0.0/Maybe-Extra#combine
>
> You can also check that function's source code.
>
> Am 08.10.2016 um 17:03 schrieb Max Goldstein :
>
> The Elm compiler is correctly telling you that your list is a list of
> functions that produce Maybes, but you said you had a list of Maybes.
>
> If you wanted the first Just regardless of other values: List.filterMap
> identity >> List.head
>
> My advice is to check the lengths of the original list and the filterMap'd
> list. If they're equal, take the head of the filterMap'd list. If not,
> Nothing.
>
> --
> 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.
>

-- 
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.


[elm-discuss] Re: Which text editor do you prefer for Elm?

2016-10-08 Thread Thomas Droxler
 Hi everyone, 

I'm using vim (neovim) with `ElmCast/elm-vim` and I'm currently integrating 
elm to Sarsi  (see PR 
). This allows me to automatically 
jump on error (no need to read the file/line/column in the error message), 
I must say it's a key feature for me, I'm using Sarsi daily with Scala at 
work and it rocks. 
Moreover, as explain in the Sarsi doc, I'm also using entr 
, which allows me to automatically launch 
`elm-make` when I save a file.

Anyway, we're also looking for someone to create a `sarsi-atom` or any text 
editor, don't hesitate. :-)

Le mercredi 10 août 2016 12:47:34 UTC+2, Rupert Smith a écrit :
>
> I'm trying the Elm emacs mode, but it is pretty bad. If I select and 
> indent a whole file for example all the import statements and statements 
> within a let .. in get indented +1 more level as you go down the list. 
> Sometimes it crashes and busy spins Emacs too.
>
> Something better would be appreciated. :-)
>

-- 
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.


[elm-discuss] Creating an API to be consumed by JS developers

2016-10-08 Thread Dave Ford
My experience with compile-to-js languages include: GWT, Dart and 
TypeScript.

GWT was very good at *calling* JS libraries. Almost zero friction. But not 
so, in the other direction. Creating API's to be consumed by JS was so ugly 
that I can confidently say that it was not worth it. Unless you are 
creating an API that has a very small surface area to functionality ration 
(like maybe a spell checker).

Dart has a similar story to GWT. 

By far the best inter-op story is TypeScript. If you write a lib 
in TypeScript it can be consumed by JS as-is. No special anything is 
needed. 

So my question is, where does Elm fall in this spectrum. Is it advisable to 
create an api in Elm to be consumed by JS developers?

-- 
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.


Re: [elm-discuss] Maybe.andThen with List.foldr type trick?

2016-10-08 Thread Janis Voigtländer
http://package.elm-lang.org/packages/elm-community/maybe-extra/2.0.0/Maybe-Extra#combine

You can also check that function's source code. 

> Am 08.10.2016 um 17:03 schrieb Max Goldstein :
> 
> The Elm compiler is correctly telling you that your list is a list of 
> functions that produce Maybes, but you said you had a list of Maybes.
> 
> If you wanted the first Just regardless of other values: List.filterMap 
> identity >> List.head
> 
> My advice is to check the lengths of the original list and the filterMap'd 
> list. If they're equal, take the head of the filterMap'd list. If not, 
> Nothing.
> 
> -- 
> 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.


Re: [elm-discuss] Re: Pattern matching functions

2016-10-08 Thread 'Andrew Radford' via Elm Discuss
Well the idea is to add a *different* keyword to make a function, using 
similar syntax to case/of .  As above, you can see F# uses the 'function' 
keyword, which TBH I'm not  huge fan of, it's really hard to google.

Elm already has syntax of convenience like this, for example instead of 
having to write a function for a record field access like this:

'\x -> x.foo'

you can just do:

'.foo'

The only reason for this is clearer, more concise code. So too would be the 
purpose behind the pattern matching function. It's quite a useful thing in 
F#, and one quite often used with |> (which I hear Elm inherited from F#).


On Saturday, 8 October 2016 15:23:29 UTC+1, Joey Eremondi wrote:
>
> Much like how we don't have where clauses, the general approach in Elm is 
> to only have one syntax for a particular thing. 
>
> On Oct 8, 2016 7:18 AM, "Luke Westby"  
> wrote:
>
>> case .. of statements are only expressions, not functions, so you'll 
>> need to continue wrapping those statements with \x -> case x of
>>
>>
>>

-- 
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.


Re: [elm-discuss] View: Model -> Html Msg

2016-10-08 Thread Max Goldstein
Syntactically, it's just like List Int. Msg is a type parameter of Html. 

Semantically, Html is not a data structure. It's a somewhat magical thing that 
can produce messages when the user interacts with it. The type parameter tells 
you what those messages are. 

-- 
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.


Re: [elm-discuss] View: Model -> Html Msg

2016-10-08 Thread Joey Eremondi
Exactly, it's a type parameter. Html is parameterized by the type of
messages the form can produce.

On Oct 8, 2016 9:25 AM, "Dave Ford"  wrote:

> I understand this function signature:
>
> update: Msg -> Model -> Model
>
> to mean the function takes two inputs, a Msg and a Model and returns a
> Model. Correct?
>
> But I don't understand this function signature:
>
> view: Model -> Html Msg
>
> It seems that the view function takes a Model and returns an Html. What
> exactly does the Msg mean in this context? Is it a type parameter to Html?
> Like Html in Java?
>
> Thanks.
>
> --
> 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.


Re: [elm-discuss] In

2016-10-08 Thread Joey Eremondi
Nothing except when paired with a let.

You do
  let
x = foo
y = bar
   ...
  in baz

This let's you break up large expressions, and avoid recomputing values
that are used more than once.

On Oct 8, 2016 9:26 AM, "Dave Ford"  wrote:

> What does the in keyword do?
>
> --
> 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.


[elm-discuss] In

2016-10-08 Thread Dave Ford
What does the in keyword do?

-- 
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.


Re: [elm-discuss] Maybe.andThen with List.foldr type trick?

2016-10-08 Thread Joey Eremondi
Oops, in the first case it should return Just [], not []

On Oct 8, 2016 9:02 AM, "Joey Eremondi"  wrote:

> I'm not sure using and then will work like this in the accumulator, you're
> giving it a list of thunks, but andThen tries to chain functions together,
> and your functions don't chain like that.
>
> How about this:
>
> forMaybe list = case list of
>   [] -> []
>   hm::tm -> hm `andThen` \h ->
> (forMaybe tm) `andThen` \t -> Just (h::t)
>
> I apologize for typos, I'm on my phone. This is basically what the forM
> function does in Haskell, it works with any type with an andThen, and some
> wrapper to put a value in the type (Just in the case of Maybe).
>
> On Oct 8, 2016 8:42 AM, "Duane Johnson"  wrote:
>
>> To avoid the XY problem: I'm aiming to create a function that will take a
>> List (Maybe a) and return a Maybe (List a), where the result will be
>> Nothing if ANY of the (Maybe a)s are Nothing, otherwise it will be a list
>> of just the "a"s.
>>
>> Here's where I'm getting tripped up in that quest, however: when I
>> manually combine a list of numbers (0 through 3) things work fine:
>>
>> ```elm
>> {-| This works -}
>> test =
>> Just 0) `Maybe.andThen` (\_ -> Just 1)) `Maybe.andThen` (\_ ->
>> Just 2)) `Maybe.andThen` (\_ -> Just 3))
>> ```
>>
>> but when I try to use `foldr` and `andThen`, it fails:
>>
>> ```elm
>> {-| This does NOT work -}
>> test : Maybe number
>> test =
>> let
>> func =
>> Maybe.andThen
>>
>> acc =
>> (Just 0)
>>
>> list =
>> [ (\_ -> Just 1), (\_ -> Just 2), (\_ -> Just 3) ]
>> in
>> List.foldr func acc list
>> ```
>>
>> I get the error:
>>
>> ```
>> The 3rd argument to function `foldr` is causing a mismatch:
>>
>> Function `foldr` is expecting the 3rd argument to be:
>>
>> List (Maybe a)
>>
>> But it is
>>
>> List (a -> Maybe number)
>> ```
>>
>> When I change it and remove the anonymous functions in the list (i.e.
>> ```list = [ Just 1, Just 2, Just 3 ]```) I get a new error, which I believe
>> is leading me down a wrong path (Function `foldr` is expecting the 2nd
>> argument to be `a -> Maybe b` But it is `Maybe number`).
>>
>> Any hints here? I've been hitting my head against the wall for a few
>> hours. Any help would be appreciated. (Is this an Elm bug?)
>>
>> --
>> 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.


Re: [elm-discuss] Maybe.andThen with List.foldr type trick?

2016-10-08 Thread Joey Eremondi
I'm not sure using and then will work like this in the accumulator, you're
giving it a list of thunks, but andThen tries to chain functions together,
and your functions don't chain like that.

How about this:

forMaybe list = case list of
  [] -> []
  hm::tm -> hm `andThen` \h ->
(forMaybe tm) `andThen` \t -> Just (h::t)

I apologize for typos, I'm on my phone. This is basically what the forM
function does in Haskell, it works with any type with an andThen, and some
wrapper to put a value in the type (Just in the case of Maybe).

On Oct 8, 2016 8:42 AM, "Duane Johnson"  wrote:

> To avoid the XY problem: I'm aiming to create a function that will take a
> List (Maybe a) and return a Maybe (List a), where the result will be
> Nothing if ANY of the (Maybe a)s are Nothing, otherwise it will be a list
> of just the "a"s.
>
> Here's where I'm getting tripped up in that quest, however: when I
> manually combine a list of numbers (0 through 3) things work fine:
>
> ```elm
> {-| This works -}
> test =
> Just 0) `Maybe.andThen` (\_ -> Just 1)) `Maybe.andThen` (\_ ->
> Just 2)) `Maybe.andThen` (\_ -> Just 3))
> ```
>
> but when I try to use `foldr` and `andThen`, it fails:
>
> ```elm
> {-| This does NOT work -}
> test : Maybe number
> test =
> let
> func =
> Maybe.andThen
>
> acc =
> (Just 0)
>
> list =
> [ (\_ -> Just 1), (\_ -> Just 2), (\_ -> Just 3) ]
> in
> List.foldr func acc list
> ```
>
> I get the error:
>
> ```
> The 3rd argument to function `foldr` is causing a mismatch:
>
> Function `foldr` is expecting the 3rd argument to be:
>
> List (Maybe a)
>
> But it is
>
> List (a -> Maybe number)
> ```
>
> When I change it and remove the anonymous functions in the list (i.e.
> ```list = [ Just 1, Just 2, Just 3 ]```) I get a new error, which I believe
> is leading me down a wrong path (Function `foldr` is expecting the 2nd
> argument to be `a -> Maybe b` But it is `Maybe number`).
>
> Any hints here? I've been hitting my head against the wall for a few
> hours. Any help would be appreciated. (Is this an Elm bug?)
>
> --
> 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.


[elm-discuss] Maybe.andThen with List.foldr type trick?

2016-10-08 Thread Duane Johnson
To avoid the XY problem: I'm aiming to create a function that will take a
List (Maybe a) and return a Maybe (List a), where the result will be
Nothing if ANY of the (Maybe a)s are Nothing, otherwise it will be a list
of just the "a"s.

Here's where I'm getting tripped up in that quest, however: when I manually
combine a list of numbers (0 through 3) things work fine:

```elm
{-| This works -}
test =
Just 0) `Maybe.andThen` (\_ -> Just 1)) `Maybe.andThen` (\_ -> Just
2)) `Maybe.andThen` (\_ -> Just 3))
```

but when I try to use `foldr` and `andThen`, it fails:

```elm
{-| This does NOT work -}
test : Maybe number
test =
let
func =
Maybe.andThen

acc =
(Just 0)

list =
[ (\_ -> Just 1), (\_ -> Just 2), (\_ -> Just 3) ]
in
List.foldr func acc list
```

I get the error:

```
The 3rd argument to function `foldr` is causing a mismatch:

Function `foldr` is expecting the 3rd argument to be:

List (Maybe a)

But it is

List (a -> Maybe number)
```

When I change it and remove the anonymous functions in the list (i.e.
```list = [ Just 1, Just 2, Just 3 ]```) I get a new error, which I believe
is leading me down a wrong path (Function `foldr` is expecting the 2nd
argument to be `a -> Maybe b` But it is `Maybe number`).

Any hints here? I've been hitting my head against the wall for a few hours.
Any help would be appreciated. (Is this an Elm bug?)

-- 
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.


Re: [elm-discuss] Re: Pattern matching functions

2016-10-08 Thread Joey Eremondi
Much like how we don't have where clauses, the general approach in Elm is
to only have one syntax for a particular thing.

On Oct 8, 2016 7:18 AM, "Luke Westby"  wrote:

> case .. of statements are only expressions, not functions, so you'll need
> to continue wrapping those statements with \x -> case x of
>
> --
> 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.


Re: [elm-discuss] Re: No Runtime Exceptions - Still not computing

2016-10-08 Thread Martin Janiczek
Dave, how do you think about JavaScript Promises? Where you code for the 
happy path (the chain of Promise.resolve().then().then().then()), any of 
which can throw, and have a .catch() handler that catches whatever the 
thrown value was and does something about it.
The Elm Result type is very similar to this.

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


Again, a specific example would help. Elm programs are not written the way 
C, C#, Java programs are written. Clojure is closer but because of Java 
interop reasons hasn't adopted much of the Maybe / Result / ... goodness 
and instead has nils like Java has. In Elm the erorrs are explicit (like 
you say, part of the return type). 
Read: http://blog.jenkster.com/2016/06/how-elm-slays-a-ui-antipattern.html 
for how Elm solves the Server Down error you mentioned.

Malformed JSON is also reported not with exceptions but with Result. Either 
you get your value in Ok, or helpful error message in Err. You have to 
handle both cases, it doesn't propagate up, it doesn't throw a runtime 
exception, the user sees what you decided to show him in that scenario. 
Essentially the Elm compiler tells you "This could blow up - you told me 
what to do if the JSON is OK, but what if it is not?"

On Friday, October 7, 2016 at 10:05:50 PM UTC+2, Dave Ford wrote:
>
>
>
> On Fri, Oct 7, 2016 at 11:33 AM, Kasey Speakman  > wrote: 
>>
>> Then at the edge of the application, I can deal with the errors
>>
> Yes. This is what I am trying to figure out. How to deal with that class 
> of errors at the "edge". 
>  
> Thanks.
>
>

-- 
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.


[elm-discuss] Pattern matching functions

2016-10-08 Thread 'Andrew Radford' via Elm Discuss
In F# there are pattern matching case/of statements can be written as 
functions, which is handy for composing with other functions, piping with 
|> etc:

let foo1 x = 
match x with
| 1 -> "one"
| _ -> "not one"
let foo2 = function 
| 1 -> "one" 
| _ -> "not one"


Has there been any consideration for something similar in Elm (or is there 
something in Elm already!) - I find myself often wrapping case/of  in 
lambdas, which is no big deal but would be a little nice to use it directly.

 

-- 
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.


Re: [elm-discuss] No Runtime Exceptions - Still not computing

2016-10-08 Thread Joey Eremondi
Do not use Either. The Result type in the standard library is the same, but
with the names more intuitive.

On Oct 7, 2016 11:58 PM, "Arthur Welf"  wrote:

> If you want error messages, you can use type Either:
>
> type Either a b
> = Left a
> | Right b
>
> You define the set of values which are acceptable as arguments by your
> function, and they will be executed in the Right branch. Every time your
> function receives an unacceptable argument, it goes to the Left branch and
> you can encode for it desired error message for that error.
>
> You can look at the realisation of the type and functions with this type
> here: https://github.com/imeckler/either/blob/master/Either.elm
>
> 7 окт. 2016 г., в 4:48, Dave Ford  написал(а):
>
> Thanks Joey.
>
>
>> 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.
>>
> You mean, do exactly like I showed in the java newbie example? What would
> be considered an anti-pattern in java? How is this a good thing? It seems
> like a step backwards.
>
> Often there is no way to "handle" the error. There is no sensible default.
> It's a programmer error and throwing an exception is the most logical thing
> to do.
>
> Unless I am missing some key concept, this will make your programs less
> reliable. True, there will be no runtime exception. But there will be bugs.
> And more noise.
>
> Again, I will admit that I am new to Elm. And may be missing something. I
> totally get the whole "maybe" thing. And I see the advantage of that.
>
> But, if I am not mistaken, we are back to C in the sense of "no throw"?
> C#, Java, JavaScript, and Scala have the keyword throw. VisualBasic,
> Python, Ruby, F# and Clojure have raise.
>
> Is there no throw/raise in Elm? We must use "return" for both standard
> return and error return. Is that correct?
>
> I'm not trying to be a troll. There are lots of things I love about Elm.
> I'm just trying to understand the language. Thanks.
>
>
>
> --
> 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.
>

-- 
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.