I have an assignment where we are not supposed to use any higher order functions, could a list comprehension be classified as a higher order function?
A list comprehension in Haskell is just syntactic sugar. It is defined in the Haskell 2010 Report here like so:
[ e | True ]          = [e]
[ e | q ]             = [ e | q, True ]
[ e | b, Q  ]         = if b then [ e | Q ] else []
[ e | p <- l, Q ]     = let ok p = [ e | Q ]
                            ok _ = []
                        in concatMap ok  l
[ e | let decls, Q ]  = let decls in [ e | Q ]
Note the use of Q, which ranges over qualifiers (which can include functions), in the patterns. So the answer is yes, a list comprehension is higher-order.
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