Now I know that after I declare function signature with Haskell, I can do pattern matching with function overloading like so:
frog :: Int -> String
frog 1 = "Ribbit"
frog 7 = "Croak"
frog 12 = "Pop!"
frog x = replicate x "Z"
I know I also can use guards in a similar fashion:
frog :: Int -> String
frog x =
| x == 1 = "Ribbit"
| x == 7 = "Croak"
| x == 12 = "Pop!"
| otherwise = replicate x "Z"
However I would rather prefer to combine the two ways using both a Boolean guard and a pattern to determine which arm would be executed. Something similar to this rust snippet:
fn frog(x: u32) -> String {
match x {
k if k >= 1000 => todo!()
k if k >= 100 => todo!()
k if k >= 10 => todo!()
9 | 8 | 7 => todo!()
6 | 5 | 4 => todo!()
3 => todo!()
2 => todo!()
1 => todo!()
0 => todo!()
}
}
I would like to know if that's possible to do in Haskell, and if so how to do it. Thank you in advance