roc test pa2html/main.roc
Roc application crashed with this message:
dispatch on a value that can never exist
── ✗ fail ──────────────────────────────────────── /home/rw/media/repos/roc/plainaipha/pa2html/lib/Pa2Html.roc:18:3
expect [ ".TL Go Sleep" ] |> transform() |> List.is_eq(["<h1>Go Sleep</h1>", "<hr>"])
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
Ran 45 tests in 17.6 ms. (cached):
44 passed
1 failed
0 compiler errors
Changed Util.roc to and it worked:
Util :: [].{
extract_oneliner : _, List(Str) -> _
extract_oneliner = |prefix, lst| {
pref = ".".concat(prefix)
match lst {
[first, ..] => if first.starts_with(pref) Ok(first.drop_prefix(pref).trim()) else Err(PrefixNotFound)
_ => Err(ListHasNoHeading)
}
}
expect "TL" |> extract_oneliner([".TL Hello"])? |> Str.is_eq("Hello")
expect "TL" |> extract_oneliner([".TA Hello"]) |> Try.is_eq(Err(PrefixNotFound))
expect "TL" |> extract_oneliner([]) |> Try.is_eq(Err(ListHasNoHeading))
apply = |lines, functions| {
lines_lists(lines)
|> List.join_map(|list_list| functions.join_map(|f| f(list_list)))
}
expect apply(["A"], [|_| ["A"], |_| ["B"], |_| ["C"]]) |> List.is_eq(["A", "B", "C"])
expect apply(["A"], [|a| a, |a| a]) |> List.is_eq(["A", "A"])
}
lines_lists = |input_lines| {
aux = |lines, acc|
match lines {
[] => acc
[_, .. as t] => aux(t, acc.append(lines))
}
aux(input_lines, [])
}
expect [1, 2, 3] |> lines_lists |> List.is_eq([[1, 2, 3], [2, 3], [3]])
Is this kind of practice not encouraged or allowed? I mean writing the functions outside the scope and exporting them like this:
Util :: [].{
extract_oneliner = extract_oneliner
apply = apply
}
extract_oneliner .....
appply ....
Yes, I do this all the time, I find that it makes it easier to read and understand the type if the bulk of the implementation is outside. That said I'm not sure apply = apply will work, I would use two different names, e.g., apply = apply_helper or something. I'm not aware of any conventions for the name, but I've seen "help" and "helper" used a few times by others, so that's what I'm using too.
I tried to give it a name like apply = apply_impl
Got the same error, it is maybe a weird edge case or so, idk. It works, with the changed Util.roc so I will go with that.
Last updated: Sep 03 2026 at 15:16 UTC