reset password
Author Message
jungsoolim
Posts: 38
Posted 22:40 Feb 16, 2019 |

How do I construct nested Guard statement?

Thanks!

jpatel77
Posts: 44
Posted 22:47 Feb 16, 2019 |

I do not think it is possible in a straight forward way, however you may

  • use if... else inside a particular guard case
  • put an explicit guard case for each possible combination of nested if...elses

I haven’t come across any other literal way to achieve this.

Last edited by jpatel77 at 22:48 Feb 16, 2019.
jungsoolim
Posts: 38
Posted 22:49 Feb 16, 2019 |

I see... Thanks! Soo

bfazeli
Posts: 6
Posted 22:49 Feb 16, 2019 |

Guard statements aren’t meant to be nested in Haskell. Alternatively you can use cases

https://stackoverflow.com/questions/34124558/is-it-possible-to-nest-guards-in-haskell

Last edited by bfazeli at 23:41 Feb 16, 2019.