Just getting started in Haskell, and I'm trying to figure out the best way to assign multiple variables based on a single condition. So far I've just been packing and unpacking Tuples. Is there a better/more idiomatic way?
(var1, var2, var3) =
if foo > 0
then ("Foo", "Bar", 3)
else ("Bar", "Baz", 1)
Also curious about the cost of packing and unpacking the Tuples. If I'm reading this correctly, it seems like this gets optimized away in functions, but not sure if that's the case with an assignment.
(a:b:c:rest) = [1,2,3,4,5,6]wherea = 1,b = 2,c = 3, andrest = [4,5,6]. Furthermore, this is only necessary inletandwherestatements, not in base expression level."Bar"is actually represented at runtime... ;-)