Probably a silly question but I can't for the life of me figure this out.
I want to append to the end of a list based on a series of if statements.
In python (or most other languages I am familiar with) I could do something like this:
x = ["hi"]
if True:
x.append("hello")
if not True:
x.append("wait a minute...")
if True:
x.append("goodbye")
Which would give me:
['hi', 'hello', 'goodbye']
How does one achieve such a thing in Haskell?
I can get as far as:
res :: [[Char]]
res =
let x = ["Hi"]
in
if (True)
then x ++ ["hello"]
... what goes here???
else x
Or am I going about this totally wrong?
I am very new to Haskell so please don't bite...
Idiomatically,
x = concat [ [ "hi" ],
[ "hello" | True ],
[ "wait a minute..." | not True ],
[ "goodbye" | True ] ]
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With