With the intention of performing much more complex dictionary updates (involving Dict.update
), I'm currently stuck on the following:
list = ["a", "b", "c", "d", "e", "f"]
{- ["a", "b", "c", "d", "e", "f"] : List Str-}
d = List.walkWithIndex list (Dict.empty {}) \state, elem, i -> Dict.insert state elem i
{- @Dict { buckets: [{ dataIndex: 5, distAndFingerprint: 466 }, { dataIndex: 3, distAndFingerprint: 721 }, { dataIndex: 4, distAndFingerprint: 977 }, { dataIndex: 1, distAndFingerprint: 1231 }, { dataIndex: 2, distAndFingerprint: 1487 }, { dataIndex: 0, distAndFingerprint: 1634 }, { dataIndex: 0, distAndFingerprint: 0 }, { dataIndex: 0,
distAndFingerprint: 0 }, { dataIndex: 0, distAndFingerprint: 0 }, { dataIndex: 0, distAndFingerprint: 0 }, { dataIndex: 0, distAndFingerprint: 0 }, { dataIndex: 0, distAndFingerprint: 0 }, { dataIndex: 0, distAndFingerprint: 0 }, { dataIndex: 0, distAndFingerprint: 0 }, { dataIndex: 0, distAndFingerprint: 0 }, { dataIndex: 0, distAndFingerprint: 0 }], data: [("a", 0), ("b", 1), ("c", 2), ("d", 3), ("e", 4), ("f", 5)], maxBucketCapacity: 12, maxLoadFactor: 0.8, shifts: 60 } : Dict Str U64 -}
Dict.get d "c"
{- Err KeyNotFound : Result U64 [KeyNotFound] -}
{- Tried alternatively with the following, but the effect was equivalent:
d = List.walkWithIndex list (Dict.empty {}) \state, elem, i -> state |> Dict.insert elem i -}
whereas
d =
Dict.empty {}
|> Dict.insert "a" 0
|> Dict.insert "b" 1
|> Dict.insert "c" 2
|> Dict.insert "d" 3
|> Dict.insert "e" 4
|> Dict.insert "f" 5
{- @Dict { buckets: [{ dataIndex: 3, distAndFingerprint: 497 }, { dataIndex: 4, distAndFingerprint: 753 }, { dataIndex: 5, distAndFingerprint: 1008 }, { dataIndex: 2, distAndFingerprint: 1263 }, { dataIndex: 1, distAndFingerprint: 1518 }, { dataIndex: 0, distAndFingerprint: 1551 }, { dataIndex: 0, distAndFingerprint: 0 }, { dataIndex: 0, distAndFingerprint: 0 }, { dataIndex: 0, distAndFingerprint: 0 }, { dataIndex: 0, distAndFingerprint: 0 }, { dataIndex: 0, distAndFingerprint: 0 }, { dataIndex: 0, distAndFingerprint: 0 }, { dataIndex: 0, distAndFingerprint: 0 }, { dataIndex: 0, distAndFingerprint: 0 }, { dataIndex: 0, distAndFingerprint: 0 }, { dataIndex: 0, distAndFingerprint: 0 }], data: [("a", 0), ("b", 1), ("c", 2), ("d", 3), ("e", 4), ("f", 5)], maxBucketCapacity: 12, maxLoadFactor: 0.8, shifts: 60 } : Dict Str (Num *) -}
Dict.get d "c"
{- Ok 2 : Result (Num *) [KeyNotFound] -}
Please, note that equivalent behaviour is observed when utilising List.walk
as well.
Could somebody please point me to where the issue in my code is?
Thank you for your time!
Looks like a bug to me. I think these should produce the same thing.
Thank you for confirming!
Yes, the data portions of those are indeed the same, and I'd expect equivalent behaviour as well ( I just wasn't sure if I was using the correct syntax, even though I tried multiple variations of positioning parentheses).
I've been getting some odd functionality when trying to utilise Dict.update
and (independently) when using List
as the state.
I'll raise a GitHub ticket about this when I get a chance.
Hristo has marked this topic as resolved.
Just adding a bit more context - this only occurs in Roc's REPL.
In traditionally compiled Roc, this hasn't been reproduced.
Cool. So bug on the dev backend
Last updated: Jul 06 2025 at 12:14 UTC