Skip to content

Conversation

@lue-bird
Copy link
Collaborator

@lue-bird lue-bird commented Dec 29, 2025

List.foldr (::) [] list
--> list

List.foldl (::) [] list
--> List.reverse list

Set.foldr (::) [] set
--> Set.toList set

-- same for foldr, when `expectNaN` is not enabled
Set.foldl Set.insert Set.empty set
--> set

Dict.foldr (\k _ ks -> k :: ks) [] dict
--> Dict.keys dict

Dict.foldr (\_ v vs -> v :: vs) [] dict
--> Dict.values dict

-- same for foldr, when `expectNaN` is not enabled
Dict.foldl Dict.insert Dict.empty dict
--> dict

Dict.foldr (\k v list -> ( k, v ) :: list) Dict.empty dict
--> Dict.toList dict

Includes some nice improvements to normalize.

There are so many more simplifications of this kind (filter, map, fromList, ..., the append ones with flipped arguments, even combining into non-empty accumulator as union, ++ etc). I'll probably try to do something more useful next 😅

@jfmengels
Copy link
Owner

Looking good so far to me 👍

@lue-bird lue-bird marked this pull request as ready for review December 30, 2025 00:20
to for example fix `(if c then 2 else 3) == (if c then 1 else 4)` to `False`
- Now evaluates `<`, `<=`, `>=`, `>` for any two comparable operands to for example fix `"a" < "b"` to `True`
- Now fixes `Tuple.first (Tuple.mapBoth changeFirst changeSecond tuple)` to `changeFirst (Tuple.first tuple)` instead of `Tuple.first (Tuple.mapFirst changeFirst tuple)` (same for second)
- Now recognizes more lambdas as equivalent, to for example detect equal branches like `if c then f else \a -> f a`
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Damn, that's nice! ❤️

@jfmengels
Copy link
Owner

Beautiful work here @lue-bird, thank you so much for this ❤️

@jfmengels jfmengels merged commit 2c8ab57 into jfmengels:main Dec 30, 2025
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants