6 ms·
this is not quite right. haskell and scheme have if expressions, not if statements. that's not the same as if being a function. if is not, and cannot be, a func
by disconcision 1y ago
this is not quite right. haskell and scheme have if expressions, not if statements. that's not the same as if being a function. if is not, and cannot be, a function in scheme, as it does not have scheme function semantics. specifically, it is not strict, as it does not evaluate all its subexpressions before executing. since haskell is non-strict, if can be implemented as a function, and iirc it is
- trealira 1y ago> since haskell is non-strict, if can be implemented as a function, and iirc it is "If" can be implemented as a function in Haskell, but it's not a function. You can't pass it as a higher-order function and it uses the "then" and "else" keywords, too. But you could implement it as a function if you wanted: if' :: Bool -> a -> a if' True x _ = x if' False _ y = y Then instead of writing something like this: max x y = if x > y then x else y You'd write this: max x y = if' (x > y) x y But the "then" and "else" remove the need for parentheses around the expressions.
- Zambyte 1y agoif in Scheme can be, and in some cases is, implemented as a macro though. Which has arguments and can be called like a function.