4 ms·
Agreed; neither of the translations use monads, because monads are a semantic hand-job proscribing order within a declarative language. However, Scheme is not
by chandler 18y ago
Agreed; neither of the translations use monads, because monads are a semantic hand-job proscribing order within a declarative language. However, Scheme is not a declarative language, therefore order is implied in the structure, therefore monads aren't necessary.
>> Your print-n-times doesn't return an action...
Nope, look again. It returns the results of applying `void'. Who knows what (void) may return in a loosely-typed language?
>> ...it's an imperative function that performs an action.
Well, considering Scheme is an imperative language with side-effects, it's hard to dodge such criticism.
>> The naive translations to Scheme would be as follows...
That's not a translation from Haskell to Scheme, that's writing Haskell using a prefix syntax.
>> Also, both your examples rely heavily on non-strict evaluation. 'and' and 'or' are both macros that non-strictly evaluate expressions.
I went back and re-read your original post:
>> ...you'll note that the translation, strictly evaluated, gives infinite recursion.
Mea culpa--I completely missed your point that translating from a turing complete language to a non-turing complete language might have some pitfalls.
- shrughes 18y agoThen maybe I'm misunderstanding the point of your reply. I was pointing out how monads are inconvenient to use in strictly evaluated languages. Why did you follow up with an example about how not using monads is convenient?
- chandler 18y ago>> Then maybe I'm misunderstanding the point of your reply. I was pointing out that your examples don't make sense, as it's trivial to translate the Haskell code into another general purpose language (such as Scheme, C, Perl, Fortran, etc), while impossible to translate into an eager (strictly evaluated) language (such as...?). Additionally, the reason monads are cumbersome in other languages has nothing to do with eager/lazy evaluation, or conditional computation, and everything to do with the fact that monads exist in Haskell to solve it's sequencing problem (arising from the fact that it's a declarative language). Imperative languages have no problem with sequencing, and therefore have no need for monads.