Stream: beginners

Topic: how to develop / build in roc?


view this post on Zulip Oliver Schöning (Oct 22 2021 at 11:49):

Ok, so I would like to get familiar with roc by tweaking the examples and make them do different stuff!
But I am a spoiled JS / Elm dev who is used to having a watch command on my files or a tool like nodemon, etc.
When I tried to tweak the examples/cli/Echo.roc and ran cargo run ... it still outputs the same as before. Obviously I need to rebuild it. But I know nothing about Rust and Cargo. Could I get some tips what I need to learn to write my own example / platform?
Do I need to learn Rust / Cargo, or learn Zig?
Not asking for a step by step guide but just some pointers so that I don't sit completely in the dark with trial and error :smile:

view this post on Zulip Folkert de Vries (Oct 22 2021 at 11:51):

just cargo run examples/cli/Echo.roc will rebuild it every time, then run the fresh binary

view this post on Zulip Folkert de Vries (Oct 22 2021 at 11:51):

it will also rebuild the platform, if changes occured

view this post on Zulip Folkert de Vries (Oct 22 2021 at 11:51):

platforms must be written in something that supports the C abi. we currently have C, rust and zig examples, but e.g. c#, python or swift would also work fine

view this post on Zulip Richard Feldman (Oct 22 2021 at 12:06):

I also really need to write some documentation for this! :sweat_smile:

view this post on Zulip Oliver Schöning (Oct 22 2021 at 12:17):

@Richard Feldman
One thing I am curious about with roc:
What happens if firstName await returns an "Result err" ? How is this handled without a "try catch" ?
In JS either I use <promise>.catch or wrap things in a try catch.
But if firstName was a http request, how would this proceed? Would it just return the function right there at the error, returning some form of Result error? Or what would happen?

main : Task {} *
main =
    {} <- await (Stdout.line "What's your first name???")

    firstName <- await Stdin.line

    {} <- await (Stdout.line "What's your last name???")

    lastName <- await Stdin.line

    Stdout.line "Hi, \(firstName) \(lastName)!"

view this post on Zulip Folkert de Vries (Oct 22 2021 at 12:27):

you can always translate a <- f b into f b \a ->

view this post on Zulip Folkert de Vries (Oct 22 2021 at 12:28):

so it "just" works like andThen in elm

view this post on Zulip Oliver Schöning (Oct 22 2021 at 12:30):

Ah ok!
So a function that does http requests using await would have a "Result error value " return type? And just nicely sugars it?

view this post on Zulip Folkert de Vries (Oct 22 2021 at 12:37):

it would return a task most likely?

view this post on Zulip Oliver Schöning (Oct 22 2021 at 12:39):

Yeah sorry, I just meant something that maybe has a result but roc does not have maybe. I still I got the gist of things, I just dont not know the types yet hehe

view this post on Zulip Folkert de Vries (Oct 22 2021 at 12:42):

ah, we use Result a {} , so empty record for the "error" value


Last updated: Jul 06 2025 at 12:14 UTC