Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Difficulties in understanding this elm function

I am learning elm, I've read the documentation and now I'm trying to annotate all the examples trying to explain what happens in each function.

This exercise is taking me quite some time to understand.

  1. What does the next type annotation mean? I get the first parameter is a String and the last Html, but what about the middle one? Is it a Result which is composed by a String field and a List String field?

view : String -> Result String (List String) -> Html

  1. Almost the same as the above, what does those nested types mean?

results : Signal.Mailbox (Result String (List String))

I'll leave the async bit for another question, many thanks in advance!

like image 280
Alberto Zaccagni Avatar asked May 23 '26 19:05

Alberto Zaccagni


1 Answers

Result abstracts an operation that could succeed or fail. It is defined as

type Result error value
    = Ok value
    | Err error

If the operation succeeds the values will be Ok value, otherwise, if it fails, it will be Err error. In your case, the suceed value will be a list of strings, while the error value will be a single message.

For the second point, the thing is similar, results is a mailbox that contains a Result, which will be either Ok (List String) or Err String

like image 94
marcosh Avatar answered May 26 '26 09:05

marcosh



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!