Zulip Chat Archive
Stream: new members
Topic: What function to replace items in List
Colin ⚛️ (Jul 21 2025 at 00:39):
Can anyone provide me a function that can replace all the A with B in a list ? I tried to use an if statement with pmap or map but it requires Classical.propDecidable which is non computable.
inductive example_type
| A | B | C | D
open example_type
deriving instance Repr for example_type
def A_to_B (n : example_type) :=
if n = A then B else n
-- Want a function that takes [A, A, B, C, A, D] and becomes [B, B, B, C, B, D]
Kyle Miller (Jul 21 2025 at 01:03):
inductive example_type
| A | B | C | D
deriving DecidableEq, Repr
open example_type
def A_to_B (n : example_type) :=
if n = A then B else n
#eval [A, A, B, C, A, D].map A_to_B
-- [example_type.B, example_type.B, example_type.B, example_type.C, example_type.B, example_type.D]
Kyle Miller (Jul 21 2025 at 01:04):
Or instead of DecidableEq you can use a match:
def A_to_B (n : example_type) :=
match n with
| A => B
| _ => n
Colin ⚛️ (Jul 21 2025 at 14:46):
Thank you!
Last updated: Dec 20 2025 at 21:32 UTC