dimanche 27 décembre 2020

Can if-structures be used in Haskell list comprehensions?

Can some sort of if statement be used inside list comprehension to determine one of several outcomes for each element of a list?

Say I have a list comprehension over a list that contains elements which are either a 0 or a 1.

If the value is a 0, then the string "off" needs to be stored in another list in the same position. If the value is 1 then "on".

This is just an example. It looks easily done with recursion, but what if this needs to be done on a list of lists? Or lists of lists of lists?

Aucun commentaire:

Enregistrer un commentaire