I have an interface defined something like this:
interface LinkedList
exposes [
LinkedList,
single,
push,
pop,
toList,
concat,
walk,
empty,
]
imports []
LinkedList a := LL a
LL a : [Nil, Cons { first : a, rest : LL a}]
empty : LinkedList *
empty = @LinkedList Nil
# and some more stuff...
When I use empty
in another module, it crashes roc build
. If I redefine empty
as a function (and call it that way), it works:
empty : {} -> LinkedList *
empty = \_ -> @LinkedList Nil
Is it supposed to be possible to expose a value, or only functions?
I see I can expose other kinds of values—maybe this is a problem with the LinkedList *
type? In Scala I would have made this LinkedList[Nothing]
which is a subtype of every type. I guess *
doesn't work that way?
Oh and I see my function version is not working anyway when I try to actually add an item to the empty list.
I don't recall the details, but i know we had to do the same thing with dictionaries.
Due to exposing a Dict k v
, empty
is required to be a function.
It is related to constants and type parameters, but i don't understand the full details
Given the function version works with built-in types and interfaces, it should work with your linked list example. Would need to see more code to make a guess at the issue when adding a value.
Thanks - I will try to look at the Dict version and see how the types are written
In case you want the full background of why Dict.empty (and your LinkedList.empty) have to be functions: https://roc.zulipchat.com/#narrow/stream/304641-ideas/topic/Let-generalization.20-.20let's.20not.3F/near/318649802
Last updated: Jul 06 2025 at 12:14 UTC