Skip to content

for loops on sets don't seem to work #11

@roetlich

Description

@roetlich

In prelude/set.ptls both difference and intersection use a for comprehension on a set. Sadly, when I tried to use them, they crash :(

It can easily be "fixed" by calling toList on the set:

 intersection(a, b) = toSet(interElems)
   where interElems =
-    for elem in a
+    for elem in toList(a)
     when elem in b
     yield elem

I could make a PR with that change, but it looks less nice, and I'm assuming this is a regression (i.e. for on a Set worked at some point). A proper fix would be making for comprehensions on sets work.

If you point me to the right file(s) I could check if can fix this myself.

This is the error message I get:

-------------------------------------------------------------------------------
Type Error:

No built-in field '!getHead' for type 'PtlsSet'
-------------------------------------------------------------------------------

At (line 216 column 19) in '/Users/till/code/ptls/pointless/bin/../prelude/list.ptls'
  else [func(head(list))] ++ map(func, tail(list))
                  ^
At (line 5 column 14) in '/Users/till/code/ptls/pointless/bin/../prelude/list.ptls'
head(list) = list.!getHead
             ^
At (line 38 column 13) in '/Users/till/code/ptls/pointless/bin/../prelude/list.ptls'
  else head(lists) ++ concat(tail(lists))
            ^
At (line 37 column 17) in '/Users/till/code/ptls/pointless/bin/../prelude/set.ptls'
    for elem in a
                ^
At (line 43 column 26) in '/Users/till/code/ptls/pointless/bin/../prelude/list.ptls'
concatMap(func, lists) = lists |> map(func) |> concat
                         ^
At (line 1 column 19) in '<repl>'
difference(digits,digits)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions