r/functionalprogramming • u/ibrahimbensalah • Feb 28 '23
Question Is JSX a hidden monad bind?
Say we have this example
function Component() {
return <Layout><Page /></Layout>
}
And lets assume this is compiled to
where type of jsx is (fn, JSX.Element) => JSX.Element. For simplicity ignore that we can have multiple elements in the second argument.
jsx is not in the form of monadic bind (JSX.Element, (fn) => JSX.Element) => JSX.Element. If we ignore the laws, can we say jsx is a special case of the monadic bind function nevertheless?
15
Upvotes
View all comments
Show parent comment
3
u/antonivs Mar 01 '23
Compared to what? The major functional languages like Haskell, Ocaml, SML, and some Scheme implementations are significantly faster than Python, at least as fast as Java, and in some cases match or exceed C performance, e.g.: https://ericnormand.me/podcast/how-is-haskell-faster-than-c
But, what you may be referring to is that doing functional programming in a non-functional language like Javascript is slow. That’s going to depend a lot in what exactly you’re doing. A higher order function evaluating lots of closures is likely to be slower than an inline for loop, for example. That’s because the language doesn’t do any relevant optimizing compilation.