This topic is not about compiler development, but to discuss problems writing Roc programs in this early stage.
One of the bugs I encountered and seemingly was able to fix concerns List.walkRight. Should I simply create a branch and a pull request? Are there any naming conventions?
Yeah I think a PR would be great. We made walkRight
fairly recently. What was the problem?
I dont think we have any PR naming conventions right now
It doesn't work if the "accumulator" is not an Int, but for example a string or a record. PR created.
Maybe my biggest obstacle is not being able to split code into multiple files:
This doesn't work:
interface Dep exposes [ value ] imports []
value : Str
value = "Dep.value"
app Main provides [ main ] imports [ Dep ]
main : Str
main = Dep.value
This works:
interface Dep exposes [ value ] imports []
value : {} -> Str
value = \_ -> "Dep.value"
app Main provides [ main ] imports [ Dep ]
main : Str
main = Dep.value {}
This doesn't work:
interface Dep1 exposes [ value1 ] imports []
value1 : {} -> Str
value1 = \_ -> "Dep1.value1"
interface Dep2 exposes [ value2 ] imports []
value2 : {} -> Str
value2 = \_ -> "Dep2.value2"
app Main provides [ main ] imports [ Dep1, Dep2 ]
main : Str
main = Str.concat (Dep1.value1 {}) (Dep2.value2 {})
This doesn't work either:
interface Dep1 exposes [ value1 ] imports [ Dep2 ]
value1 : {} -> Str
value1 = \_ -> Dep2.value2 {}
interface Dep2 exposes [ value2 ] imports []
value2 : {} -> Str
value2 = \_ -> "Dep2.value2"
app Main provides [ main ] imports [ Dep1 ]
main : Str
main = Dep1.value1 {}
They all panic with different errors. It seems that currently I can only import functions from exactly one other file. BTW: I'm on MacOs.
they all hit hard asserts though? Usually module loading problems result in a deadlock
got this fixed in the PR. thanks for reporting/partially fixing!
Here's a stripped down version of another problem. It compiles but on running it reports a "pointer being freed was not allocated" error (on MacOs):
app Main provides [ main ] imports []
main : Str
main =
addText = \addedText, oldText -> Str.concat oldText addedText
List.walkRight [ "", "Very very long str" ] addText ""
It works if I use a short string, and works with the long string, too, if I switch the arguments of Str.concat
. I tried to debug it in lldb, but haven't been able to find the culprit.
Today is the first day of the Advent of Code programming contest. I'd like to "participate" using Roc as my programming language. As always, the first problem is really simple: given a list of 200 integers, find a pair where the sum is 2020 and output their product. Unfortunately, I haven't been able yet to implement this with the current trunk of the compiler. No matter which way I chose, the compiler is always yelling at me.
I'd be grateful if someone more knowledgeable in Roc / the compiler could give this a try. Link to the contest page: https://adventofcode.com
Could you a share a minimal compiling example that is similar to the problem that you are trying to solve?
Thanks for the quick reply. Lunch break is over, so it'll be a couple of hours. Would you like a complete directory like in the examples folder or just a Roc file?
You're welcome :). The full directory would probably be the easiest.
from a quick experiment, it's easy to trigger internal error: entered unreachable code: Invalid function basic value enum or layout for List.map
. I'll see if I can fix that
Here's a repository I quickly setup: https://github.com/pithub/aoc2020. It assumes the Roc repository is in a parallel directory called "lang". So I have the directories "roc/lang" and "roc/aoc2020". I chose List (List Int)
for the output format, because I had malloc/free problems with Strings, and wanted to output multiple values per test case.
Ah, I forgot to add the desired solution for the sample input:
"In this list, the two entries that sum to 2020 are 1721 and 299. Multiplying them together produces 1721 * 299 = 514579, so the correct answer is 514579."
btw thank you so much @Pit Capitain for being the first person to use Roc for Advent of Code...I'm really excited to see the bugs this will surface, and the resulting improvements to the compiler! :heart:
You're very welcome :smile: Unfortunately I haven't been able to fix some more problems - yet.
no worries! Finding out what they are is a major help on its own :big_smile:
yea so I made some steps, and I can find the correct answer, but not print it correctly, because there is a bug in Str.concat
Cool, Folkert. Any branch you can share? What do you need Str.concat
for? At least for the first challenge, we'd only need an Int
. (I also had problems using strings, so I switched to List (List Int)
for the output.)
well you need to get the result out . You could pass the result through the FFI boundary, but I wanted to print it to stdout immediately
Ah OK. I just use RocCallResult<RocList<RocList<i64>>>
to return the results.
In the meantime, I found a working solution :rock_on: And it's your sample code, Folkert, that made it possible :muscle:
Now a little bit of cleaning up and then the next day's puzzle may come!
nice!
cool! I'd love to see it, if you're comfortable sharing! :smiley:
I made some improvements here https://github.com/rtfeldman/roc/pull/756
besides all the noise of the zig formatter, it makes the compiler work again on my machine by only conditionally following the arch path, can print Result
in the repl, and allows List.map
to call closures
other builtins cannot yet call closures in all circumstances though
Day 2 could also be solved with the current Roc, and I indeed used List.map with a closure, so thank you very much Folkert for this :handshake:
The repository currently is here: https://github.com/pithub/aoc2020. If there's interest, where and how should I write about my trials and errors? I could add some notes and create branches in this repository with the different variations I tried, but maybe there's a better way?
nice very cool
If you have variations that you thought should work but don't, putting them on a branch would be reasonable. Otherwise, comments or just a text log would probably be useful.
hahaha I love that you actually used our quicksort implementation for a real solution! :joy_cat:
brilliant!
I added a document describing what I tried today, what failed and what succeeded.
wow, super helpful!
ok the original countMember
implementation should now work on trunk
!
it was complaining about keepIf
needing another argument in |> List.keepIf isGivenElement
because under those particular circumstances it was parsing isGivenElement
as an is
keyword (from when
/ is
) instead of an argument
fixed now!
I think I’m jealous of all this AOC roc code being written :p lol
Just wanted to say thank you for all the work currently going on, some of which will be immediately helpful for the next puzzles. Yesterday I had a very long work day because of a production problem, so I hadn't enough time yet to write about the Day 3 experience. All puzzles could be solved yet :+1:
Concerning the long build times for long input data: if I have time, I'll try to change the platform code to read the puzzle input from a file and pass the List (List Int)
data as a parameter to the Roc main function. This way I could avoid the long literals.
I think I’m jealous of all this AOC roc code being written :p lol
You can join the contest any time you like :smirk: Pull requests are always welcome, too...
awesome
@Pit Capitain I'll soon push a fix for the stack overflow for large literals. Just to check, were you building the compiler with --release
mode? it really speeds up the compilation process on my machine (~7 seconds to < 1)
:point_up: this is now merged into trunk
!
Thank you both. I always compiled without --release
. Not knowing Rust very well, I assumed that using it would perform more optimisations and there fore would be even slower :face_palm:
Yesterday I added a file reader effect to my platform, so currently I'm not dependent on large literals anymore. But as soon as parsing the input wouldn't work or the test data gets bigger, I would need it. I'll definitely give it a go!
Yesterday I added a file reader effect to my platform, so currently I'm not dependent on large literals anymore.
wow, I think that makes you the first person to ever solve a problem in Roc by adding a new effect to the platform! :smiley:
glad to hear that solution worked!
Yeah, it worked almost flawlessly. There were some problems, but for my usecase all went well.
@Folkert de Vries I went back to debug mode, because in release mode effects didn't work for me. The effect example had the same problem. I think the compiler reported that it couldn't find the Effect.roc
file. Seems not too hard to fix, but I preferred to refactor my code from the last days in order to be better prepared for the next puzzles...
if you have no imports in your app module (builtin modules don't count for this) you can comment out this section and --release
should work
// all the dependencies can be loaded
for dep in dependencies {
// TODO figure out how to "load" (because it doesn't exist on the file system) the Effect module
if !format!("{:?}", dep).contains("Effect") {
output.insert((*dep, LoadHeader));
}
}
in load/src/file.rs
line ~143
https://github.com/rtfeldman/roc/pull/752
this might help with that once it's done?
yup!
I'm gonna show it some more love today. I have to admit it's been challenging but I make some progress every time I touch it
Thank you Folkert, I will try this eventually. Thank you too, Lucas, but please don't change your priorities jut because of my trials. So far it has been a nice experience overall. Let's see how far I'll get if the puzzles get harder to solve...
Just a short update from AoC 2020: I could solve all puzzles so far with Roc programs (a few times externally preprocessing the puzzle input text) :thumbs_up:
Unfortunately, I'm still stuck at commit 149d10ea. The effect examples don't work on my MacBook for newer commits. Here's a short summary of the examples in trunk ("r" means building with --release
, "o" with --optimize
:
example ro r- -o --
---------------- --- --- --- ---
balance fnf fnf fnf fnf
closure ok ok ok ok
effect tmm hlt tmm hlt
hello-world ok ok ok ok
quicksort ok ok ok ok
shared-quicksort ok ok ok ok
task gaa ftr gaa ftr
fnf
FileProblem { filename: "/Users/pit/Documents/work/roc/trunk/examples/balance/Effect.roc", error: NotFound, msg: "in `load_filename`" }
compiler/load/src/file.rs:1261:46
ftr
Failed to run app after building it: Os { code: 2, kind: NotFound, message: "No such file or directory" }
cli/src/lib.rs:124:35
gaa
TODO generate aa, ab, ac, ...
compiler/types/src/types.rs:1457:9
hlt
app builds but doesn't terminate
tmm
Roc failed with message: Hit an erroneous type when creating a layout for `11.IdentId(3)`
src/lib.rs:108:17
I think you should try things without --optimize
; the uniqueness analysis is not entirely reliable
especially with effects, which are defined as a recursive tag union, type errors are almost guaranteed
the FileProblem
is something I've seen too, but it seems infrequent and hard to reproduce (I'm assuming the problem is a race condition in file.rs
)
to elaborate on that, we had some regressions in the uniqueness analysis that we decided not to look into because there's a solid chance we'll end up overhauling that whole system in the near-ish future anyway :big_smile:
I got stuck on my AoC adventure. I'll write more about this soon. Currently I'm trying to update the compiler. Unfortunately, something seems to be wrong on my Mac running Catalina. For the task example the linker says: Undefined symbols for architecture x86_64: "start", referenced from: implicit entry/start for main executable. ld: symbol(s) not found for architecture x86_64
If i add the parameters "-e _main", it says: ld: targeted OS version does not support use of thread local variables in _std.debug.panicExtra for architecture x86_64
Any hint what I could do to make the examples run again?
what language is your host written in?
looks like it might be zig?
It is the task example. I also think it could be something with zig. My version is 0.7.0+391d81a38. Btw: thank you Folkert for the fast reply.
yea its platform is written in zig, so you may have better luck with the effect
examples as a foundation
and I think we could update to the latest zig release
OK, I'll try that.
so that would be 0.7.1 I think
Yeah, I've been meaning to upgrade to the latest zig version since 0.7 came out
Has anyone ever encountered this error when trying to run cargo clippy
or cargo test
locally? I am on ubuntu 20.04.2 LTS
thread 'main' panicked at 'Could not execute clang: Os { code: 2, kind: NotFound, message: "No such file or directory" }', roc_std/build.rs:36:10
I have clang++-10
installed is there another version that I should have?
sorry if this isn't the right channel for this >.<
we use clang
there, by default the alias is clang-10
I think
so a symlink should do the trick
general fyi for everyone, you can always check the Earthfile for the complete "installation from source procedure" for debian based operating systems that is always up to date. You may still need additional dependencies to run the editor. I'll add an issue for that.
Thanks guys!
Linking did the trick! also the Earth file was super helpful! ended up fixing a couple of things thanks to it :muscle:
Nice. I'm on MacOS. I've downloaded a pre-built LLVM and then added this little function to my .zshrc
. I use this function as a prefix before every cargo command when running roc.
rocx() {
LLVM_SYS_100_PREFIX=~/Downloads/llvm PATH="$PATH:$PWD/nix/bin:~/Downloads/llvm:~/Downloads/llvm/bin" $@
}
ex: rocx cargo run repl
Although, I think I want to start using Linux for roc dev stuff. I'm on the fence between building a machine, buying a decent laptop, or dual booting on my MacBook. If anyone has any recommendations I'm open :D
in the past (last time I tried was...I think 5 years ago?) I've had problems with battery life when dual booting a MacBook to Linux - also the keyboard layout is kinda weird, because Linux wants all the keyboard shortcuts to be Ctrl- based, whereas Mac wants them all to be Cmd-based, and the MacBook keyboard doesn't have the Ctrl key in a particularly comfortable place imo
I have a Linux desktop and a Razer Blade 14" laptop, both dual booting Windows and Linux, and have been overall happy with both!
Nice I'll look into that model thanks. By the time I graduated college I was running NixOS on Mac via dual boot. XMonad and no DE smh lol. Working on a contract using emacs and elixir, those where the days. Functional down to the OS lol
I really like my DIY desktop. The case, power supply, RAM and SSD are all things that can last several upgrade cycles and save you money this way. The form factor allows for much more powerful cooling than a laptop and thus a more powerful CPU and/or graphics card.
Whenever I run a program, I get a little message 'ld: framework not found Security'
But the program runs fine anyway.
Should I make an issue?
It's mostly just so that the CLI example runs properly due to a dependency in the Rust platform that the CLI example uses @Chad Stearns
long term we wouldn't be doing that anyways. On my mac ld
also can't find the security framework so I just comment out those args
Last updated: Jul 05 2025 at 12:14 UTC