Stream: beginners

Topic: ✔ Syntax for calling "parameterless" function


view this post on Zulip Fábio Beirão (May 30 2023 at 11:15):

Total beginner here :sweat_smile:. I am trying to have a function which leverages Result but in the end I'm trying to "masquerade" a DivByZero with a more domain-oriented Tag (in this example: NotEnoughItems). I think this is a batter practice rather than just kicking a DivByZero to the consumer. However I am struggling a bit when trying to make computationWhichWoudlntWorkIfListIsEmpty into a .. "lazy" ? Or is it the case then in Roc, this value would only be evaluated if the if branch got to that point, and therefore I wouldn't need the = \_ -> syntax?

outerFunction : List (Num a) -> Result (Num a) [NotEnoughItems, SomeOtherError]
outerFunction = \items ->

    computationWhichWoudlntWorkIfListIsEmpty = \_ ->  # ❓❓
        # Here I can safely assume the list isn't empty. If the list were empty, this would result in an `Err DivByZero`
        Err SomeOtherError

    if List.len items < 1 then
        Err NotEnoughItems
    else
        computationWhichWoudlntWorkIfListIsEmpty () # ❓❓

view this post on Zulip Brendan Hansknecht (May 30 2023 at 13:26):

The general syntax is to pass in an empty record

view this post on Zulip Brendan Hansknecht (May 30 2023 at 13:26):

NoArgFunc {}

view this post on Zulip Brendan Hansknecht (May 30 2023 at 13:27):

You do need it as a function or would need to define it in the if branch. Roc is not lazy.

view this post on Zulip Fábio Beirão (May 30 2023 at 13:30):

Thank you for the reply. Okay, the empty record kind of makes sense

view this post on Zulip Notification Bot (May 30 2023 at 15:25):

Fábio Beirão has marked this topic as resolved.


Last updated: Jul 26 2025 at 12:14 UTC